Skip to content

Commit 683c43b

Browse files
committed
refactor: Migrate to Jackson 3
See [1] and [2]. Note that - `jackson-annotations` is still at version 2 in the `com.fasterxml` namespace. - `jackson-datatype-jsr310` is now built into `jackson-databind` directly and does not need to be registered. [1]: https://github.com/FasterXML/jackson/wiki/Jackson-Release-3.0 [2]: https://github.com/FasterXML/jackson/blob/main/jackson3/MIGRATING_TO_JACKSON_3.md Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
1 parent d5cb608 commit 683c43b

74 files changed

Lines changed: 282 additions & 257 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

analyzer/src/main/kotlin/PackageManagerResult.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919

2020
package org.ossreviewtoolkit.analyzer
2121

22-
import com.fasterxml.jackson.databind.annotation.JsonSerialize
23-
2422
import java.io.File
2523

2624
import org.ossreviewtoolkit.model.DependencyGraph
2725
import org.ossreviewtoolkit.model.Package
2826
import org.ossreviewtoolkit.model.ProjectAnalyzerResult
2927
import org.ossreviewtoolkit.model.utils.PackageSortedSetConverter
3028

29+
import tools.jackson.databind.annotation.JsonSerialize
30+
3131
/**
3232
* A data class representing the result of the execution of a [PackageManager]. An instance contains the single
3333
* results produced for the definition files the package manager supports. If there are global results (i.e. data that

cli-helper/src/main/kotlin/commands/CreateAnalyzerResultFromPackageListCommand.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
package org.ossreviewtoolkit.helper.commands
2121

22-
import com.fasterxml.jackson.databind.PropertyNamingStrategies
23-
import com.fasterxml.jackson.module.kotlin.readValue
24-
2522
import com.github.ajalt.clikt.parameters.options.convert
2623
import com.github.ajalt.clikt.parameters.options.default
2724
import com.github.ajalt.clikt.parameters.options.option
@@ -60,6 +57,9 @@ import org.ossreviewtoolkit.utils.ort.ORT_CONFIG_FILENAME
6057
import org.ossreviewtoolkit.utils.ort.ortConfigDirectory
6158
import org.ossreviewtoolkit.utils.spdx.SpdxExpression
6259

60+
import tools.jackson.databind.PropertyNamingStrategies
61+
import tools.jackson.module.kotlin.readValue
62+
6363
internal class CreateAnalyzerResultFromPackageListCommand : OrtHelperCommand(
6464
help = "A command which turns a package list file into an analyzer result."
6565
) {

cli-helper/src/main/kotlin/commands/ImportCopyrightGarbageCommand.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
package org.ossreviewtoolkit.helper.commands
2121

22-
import com.fasterxml.jackson.databind.ObjectMapper
23-
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator
24-
2522
import com.github.ajalt.clikt.parameters.options.convert
2623
import com.github.ajalt.clikt.parameters.options.option
2724
import com.github.ajalt.clikt.parameters.options.required
@@ -36,6 +33,9 @@ import org.ossreviewtoolkit.model.readValue
3633
import org.ossreviewtoolkit.model.yamlMapper
3734
import org.ossreviewtoolkit.utils.common.expandTilde
3835

36+
import tools.jackson.databind.ObjectMapper
37+
import tools.jackson.dataformat.yaml.YAMLGenerator
38+
3939
internal class ImportCopyrightGarbageCommand : OrtHelperCommand(
4040
help = "Import copyright garbage from a plain text file containing one copyright statement per line into the " +
4141
"given copyright garbage file."

cli-helper/src/main/kotlin/commands/classifications/ImportCommand.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
package org.ossreviewtoolkit.helper.commands.classifications
2121

22-
import com.fasterxml.jackson.module.kotlin.readValue
23-
2422
import com.github.ajalt.clikt.parameters.arguments.argument
2523
import com.github.ajalt.clikt.parameters.options.convert
2624
import com.github.ajalt.clikt.parameters.options.option
@@ -42,6 +40,8 @@ import org.ossreviewtoolkit.model.yamlMapper
4240
import org.ossreviewtoolkit.utils.common.expandTilde
4341
import org.ossreviewtoolkit.utils.spdx.SpdxSingleLicenseExpression
4442

43+
import tools.jackson.module.kotlin.readValue
44+
4545
internal class ImportCommand : OrtHelperCommand(
4646
help = "Import license classifications from supported providers to ORT format."
4747
) {

cli-helper/src/main/kotlin/commands/classifications/MergeCommand.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
package org.ossreviewtoolkit.helper.commands.classifications
2121

22-
import com.fasterxml.jackson.module.kotlin.readValue
23-
2422
import com.github.ajalt.clikt.parameters.arguments.argument
2523
import com.github.ajalt.clikt.parameters.arguments.check
2624
import com.github.ajalt.clikt.parameters.arguments.convert
@@ -35,6 +33,8 @@ import org.ossreviewtoolkit.model.toYaml
3533
import org.ossreviewtoolkit.model.yamlMapper
3634
import org.ossreviewtoolkit.utils.common.expandTilde
3735

36+
import tools.jackson.module.kotlin.readValue
37+
3838
internal class MergeCommand : OrtHelperCommand(
3939
help = "Merge multiple files with license classifications into one."
4040
) {

cli-helper/src/main/kotlin/commands/dev/RewriteTestAssetsCommand.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
package org.ossreviewtoolkit.helper.commands.dev
2121

22-
import com.fasterxml.jackson.databind.JsonNode
23-
import com.fasterxml.jackson.databind.node.ObjectNode
24-
2522
import com.github.ajalt.clikt.parameters.options.convert
2623
import com.github.ajalt.clikt.parameters.options.option
2724
import com.github.ajalt.clikt.parameters.options.required
@@ -43,6 +40,9 @@ import org.ossreviewtoolkit.model.ScanResult
4340
import org.ossreviewtoolkit.model.ScannerRun
4441
import org.ossreviewtoolkit.utils.common.expandTilde
4542

43+
import tools.jackson.databind.JsonNode
44+
import tools.jackson.databind.node.ObjectNode
45+
4646
internal class RewriteTestAssetsCommand : OrtHelperCommand(
4747
help = "Searches all test assets directories in the given ORT sources directory for recognized serialized files " +
4848
"and tries to de-serialize and serialize the file. The command can be used to update the test assets " +

cli-helper/src/main/kotlin/utils/Extensions.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121

2222
package org.ossreviewtoolkit.helper.utils
2323

24-
import com.fasterxml.jackson.databind.ObjectMapper
25-
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator
26-
2724
import java.io.File
2825
import java.nio.file.Paths
2926

@@ -73,6 +70,9 @@ import org.ossreviewtoolkit.utils.ort.CopyrightStatementsProcessor
7370
import org.ossreviewtoolkit.utils.spdx.SpdxExpression
7471
import org.ossreviewtoolkit.utils.spdx.SpdxSingleLicenseExpression
7572

73+
import tools.jackson.databind.ObjectMapper
74+
import tools.jackson.dataformat.yaml.YAMLGenerator
75+
7676
/**
7777
* Return an approximated minimal sublist of [this] so that the result still matches the exact same entries of the given
7878
* [projectScopes].

clients/fossid-webapp/src/main/kotlin/FossIdRestService.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@
2121

2222
package org.ossreviewtoolkit.clients.fossid
2323

24-
import com.fasterxml.jackson.databind.DeserializationFeature
25-
import com.fasterxml.jackson.databind.MapperFeature
26-
import com.fasterxml.jackson.databind.ObjectMapper
27-
import com.fasterxml.jackson.databind.PropertyNamingStrategies
28-
import com.fasterxml.jackson.module.kotlin.jsonMapper
29-
import com.fasterxml.jackson.module.kotlin.kotlinModule
30-
3124
import java.util.concurrent.TimeUnit
3225

3326
import okhttp3.Interceptor
@@ -61,6 +54,13 @@ import retrofit2.http.Header
6154
import retrofit2.http.Headers
6255
import retrofit2.http.POST
6356

57+
import tools.jackson.databind.DeserializationFeature
58+
import tools.jackson.databind.MapperFeature
59+
import tools.jackson.databind.ObjectMapper
60+
import tools.jackson.databind.PropertyNamingStrategies
61+
import tools.jackson.module.kotlin.jsonMapper
62+
import tools.jackson.module.kotlin.kotlinModule
63+
6464
private const val READ_TIMEOUT_HEADER = "READ_TIMEOUT"
6565

6666
interface FossIdRestService {
@@ -75,7 +75,8 @@ interface FossIdRestService {
7575
enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS)
7676
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
7777
addModule(
78-
kotlinModule().addDeserializer(PolymorphicList::class.java, PolymorphicListDeserializer())
78+
kotlinModule()
79+
.addDeserializer(PolymorphicList::class.java, PolymorphicListDeserializer())
7980
.addDeserializer(PolymorphicInt::class.java, PolymorphicIntDeserializer())
8081
.addDeserializer(PolymorphicData::class.java, PolymorphicDataDeserializer())
8182
)

clients/fossid-webapp/src/main/kotlin/LoggingInterceptor.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
package org.ossreviewtoolkit.clients.fossid
2121

22-
import com.fasterxml.jackson.databind.node.ObjectNode
23-
import com.fasterxml.jackson.databind.node.TextNode
24-
2522
import java.nio.charset.StandardCharsets
2623

2724
import okhttp3.Interceptor
@@ -33,6 +30,9 @@ import okio.GzipSource
3330

3431
import org.apache.logging.log4j.kotlin.logger
3532

33+
import tools.jackson.databind.node.ObjectNode
34+
import tools.jackson.databind.node.TextNode
35+
3636
/**
3737
* An interceptor that logs the body of FossID requests, but takes care that the credentials are not logged.
3838
* This function implementation is partly taken from the OkHttp Logging Interceptor at

clients/fossid-webapp/src/main/kotlin/PolymorphicDataDeserializer.kt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,27 @@
1919

2020
package org.ossreviewtoolkit.clients.fossid
2121

22-
import com.fasterxml.jackson.core.JsonParser
23-
import com.fasterxml.jackson.core.JsonToken
24-
import com.fasterxml.jackson.databind.BeanProperty
25-
import com.fasterxml.jackson.databind.DeserializationContext
26-
import com.fasterxml.jackson.databind.JavaType
27-
import com.fasterxml.jackson.databind.JsonDeserializer
28-
import com.fasterxml.jackson.databind.deser.ContextualDeserializer
29-
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
22+
import tools.jackson.core.JsonParser
23+
import tools.jackson.core.JsonToken
24+
import tools.jackson.databind.BeanProperty
25+
import tools.jackson.databind.DeserializationContext
26+
import tools.jackson.databind.JavaType
27+
import tools.jackson.databind.ValueDeserializer
28+
import tools.jackson.databind.deser.std.StdDeserializer
3029

3130
/**
3231
* A custom JSON deserializer implementation to deal with inconsistencies in error responses sent by FossID
3332
* for requests returning a single value. If such a request fails, the response from FossID contains an
3433
* empty array for the value, which cannot be handled by the default deserialization.
3534
*/
3635
internal class PolymorphicDataDeserializer(val boundType: JavaType? = null) :
37-
StdDeserializer<PolymorphicData<Any>>(PolymorphicData::class.java), ContextualDeserializer {
36+
StdDeserializer<PolymorphicData<Any>>(PolymorphicData::class.java) {
3837
override fun deserialize(p: JsonParser, ctxt: DeserializationContext): PolymorphicData<Any> {
3938
requireNotNull(boundType) {
4039
"The PolymorphicDataDeserializer needs a type to deserialize values!"
4140
}
4241

43-
return when (p.currentToken) {
42+
return when (p.currentToken()) {
4443
JsonToken.START_ARRAY -> {
4544
val arrayType = ctxt.typeFactory.constructArrayType(boundType)
4645
val array = ctxt.readValue<Array<Any>>(p, arrayType)
@@ -59,7 +58,7 @@ internal class PolymorphicDataDeserializer(val boundType: JavaType? = null) :
5958
}
6059
}
6160

62-
override fun createContextual(ctxt: DeserializationContext?, property: BeanProperty?): JsonDeserializer<*> {
61+
override fun createContextual(ctxt: DeserializationContext?, property: BeanProperty?): ValueDeserializer<*> {
6362
val type = property?.member?.type?.bindings?.getBoundType(0)
6463
return PolymorphicDataDeserializer(type)
6564
}

0 commit comments

Comments
 (0)