Skip to content

Commit a50a3b7

Browse files
committed
chore: Avoid the use of JsonInclude.Include.NON_DEFAULT where possible
For Kotlin, the meaning of this annotation is misleading, as it does not refer to the value explicitly assigned to a property by default, but to the value used if the underlying Java field was uninitialized. I.e., for `boolean` that would be always `false`, and for `int` it would be always `0`, see [1]. To avoid this confusion, do not use that annotation value where it can be replaced with `JsonInclude.Include.NON_EMPTY`, which also omits Java field implicit default values [2], like `null` for nullable types. [1]: FasterXML/jackson-module-kotlin#478 [2]: https://www.javadoc.io/doc/com.fasterxml.jackson.core/jackson-annotations/2.19.2/com/fasterxml/jackson/annotation/JsonInclude.Include.html#NON_EMPTY Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent 802bfa2 commit a50a3b7

File tree

5 files changed

+5
-6
lines changed

5 files changed

+5
-6
lines changed

model/src/main/kotlin/Defect.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import java.time.Instant
3030
* Instances of this class are created by advisor implementations that retrieve information about known defects in
3131
* packages.
3232
*/
33-
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
33+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
3434
data class Defect(
3535
/**
3636
* The (external) ID of this defect. This is a string used by a concrete issue tracker system to reference this

model/src/main/kotlin/DependencyGraph.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ typealias NodeDependencies = Map<DependencyGraphNode, List<DependencyGraphNode>>
7272
* Then, by following the *edges* starting from these *nodes*, the set of transitive dependencies can be determined.
7373
* The numeric indices can be resolved via the *packages* list.
7474
*/
75-
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
75+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
7676
data class DependencyGraph(
7777
/**
7878
* A list with the identifiers of the packages that appear in the dependency graph. This list is used to resolve

model/src/main/kotlin/Package.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ data class Package(
6161
/**
6262
* The set of authors declared for this package.
6363
*/
64-
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
64+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
6565
@JsonSerialize(converter = StringSortedSetConverter::class)
6666
val authors: Set<String> = emptySet(),
6767

model/src/main/kotlin/PackageReference.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ import org.ossreviewtoolkit.model.utils.PackageReferenceSortedSetConverter
3232
* A human-readable reference to a software [Package]. Each package reference itself refers to other package
3333
* references that are dependencies of the package.
3434
*/
35-
// Do not serialize default values to reduce the size of the result file.
36-
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
35+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
3736
data class PackageReference(
3837
/**
3938
* The identifier of the package.

model/src/main/kotlin/Project.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ data class Project(
5858
/**
5959
* The set of authors declared for this project.
6060
*/
61-
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
61+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
6262
@JsonSerialize(converter = StringSortedSetConverter::class)
6363
val authors: Set<String> = emptySet(),
6464

0 commit comments

Comments
 (0)