-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If the value wrapped in value class
is null
, it is not excluded from serialization
#625
Comments
Wrong issue tracker, will transfer. |
…lude.NonNull annotation(FasterXML#625)
@tmdgusya If it seems to be fixed, I will introduce the changes to |
@k163377 oh thank you |
@tmdgusya Does this mean that Kogera does fix the issue? |
@cowtowncoder I haven't checked yet. |
I checked with import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
class JsonIncludeNonNullTest {
@JvmInline
value class Primitive(val v: Int)
@JvmInline
value class NonNullObject(val v: String)
@JvmInline
value class NullableObject(val v: String?)
@JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.NON_NULL)
data class Dto(
val pN: Primitive? = null,
val nnoN: NonNullObject? = null,
val noNn: NullableObject = NullableObject(null),
val noN1: NullableObject? = null,
val noN2: NullableObject? = NullableObject(null),
val map: Map<Any, Any?> = mapOf("no" to NullableObject(null))
)
@Test
fun test() {
val mapper = jacksonObjectMapper()
val dto = Dto()
println(mapper.writeValueAsString(dto)) // -> {"noNn":null,"noN2":null,"map":{"no":null}}
}
} This problem is caused by Alternatively, there may be room to interpret this as "the value on |
value class
is null
, it is not excluded from serialization
The title has been edited to match the remaining current issue. |
Describe the bug
If a Dto contains fields of value class type and the value is null, it is not excluded from serialization with @JsonInclude(JsonInclude.Include.NON_NULL).
The only working workaround I've found is to use JsonInclude.Include.CUSTOM with valueFilter { object == null }
Version information
2.14.2
To Reproduce
Result for NonNullDto:
{"wrapped":null}
Result for CustomDto:
{}
Expected behavior
JsonInclude.Include.NON_NULL should exclude null values for kotlin value classes.
Additional context
Kotlin version: 1.8.10
The text was updated successfully, but these errors were encountered: