You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Related with issue #3481 and PR #3486 . If we enable afterburner module, the serializer will skip custom include filter for fields with null values and always include them in the serialized json string.
Version information
jackson version >= 2.14
To Reproduce
Let me use Kotlin as the programming language, but I think it's nothing to do with the Kotlin module.
Suppose we have the filter:
classCustomFilter {
overridefunequals(other:Any?): Boolean {
println("Filter called") // Print something to show that the filter gets calledreturntrue// Always filter out
}
}
and the simple data class
data classUser(
valname:String,
@JsonInclude(JsonInclude.Include.CUSTOM, valueFilter =CustomFilter::class)
valphoneNo:String?
)
Let's create an ObjectMapper
val mapper =ObjectMapper().registerKotlinModule().registerModule(AfterburnerModule()) // Kotlin and Afterburner modules are registered
Serialize the data:
val user =User("Alice", null) // phoneNo is nullval jsonString = mapper.writeValueAsString(user)
println(jsonString)
We got the result:
{"name":"Alice","phoneNo":null}
We can see that a) the filter is not called (or it will print "Filter called") and b) the field with null value is serialized but we expect it not get serialized.
Expected behavior
If we change the mapper creation and do not register the afterburner module like this:
val mapper =ObjectMapper().registerKotlinModule() // Only Kotlin module is registered
Just change the single line above and we will get the expected result:
Filter called
{"name":"Alice"}
Additional context
The root cause is the incomplete change in PR #3486. We changed the behavior of BeanPropertyWriter, but there are several subclasses of BeanPropertyWriter in the afterburner module (most noticeable one is ObjectFieldPropertyWriter). And the code resides in these classes is not changed in the PR, which causes inconsistent behavior. I suggest reviewing and modifying the related code in the afterburner module to keep the consistent behavior, or rollback the previous change #3486 (and subsequent changes if possible) to revert to the original but consistent behavior.
The text was updated successfully, but these errors were encountered:
aerisnju
changed the title
Filter annotated by JsonInclude.Include.CUSTOM does not got called if the field is null with afterburner module registered
Filter annotated by JsonInclude.Include.CUSTOM does not get called if the field is null with afterburner module registered
Dec 5, 2022
Ok. Afterburner is challenging for this reason (ditto for Blackbird). I don't have a good solution to offer as part of the challenge is test coverage; how to automate things to test both with and without AB/BB all regular databind tests, but ideally with minimal duplication of test code.
I need to move the issue to Afterburner repo as it needs to be fixed there.
Or rather, I think I'll just create a separate one there, link to this one.
I probably won't have time to work on this myself but this is something for which making PR might be simple enough to do -- add test(s) first on Afterburner/Blackbird side, then modify handling.
Describe the bug
Related with issue #3481 and PR #3486 . If we enable afterburner module, the serializer will skip custom include filter for fields with
null
values and always include them in the serialized json string.Version information
jackson version >= 2.14
To Reproduce
Let me use Kotlin as the programming language, but I think it's nothing to do with the Kotlin module.
Suppose we have the filter:
and the simple data class
Let's create an
ObjectMapper
Serialize the data:
We got the result:
We can see that a) the filter is not called (or it will print "Filter called") and b) the field with null value is serialized but we expect it not get serialized.
Expected behavior
If we change the mapper creation and do not register the afterburner module like this:
Just change the single line above and we will get the expected result:
Additional context
The root cause is the incomplete change in PR #3486. We changed the behavior of
BeanPropertyWriter
, but there are several subclasses ofBeanPropertyWriter
in the afterburner module (most noticeable one isObjectFieldPropertyWriter
). And the code resides in these classes is not changed in the PR, which causes inconsistent behavior. I suggest reviewing and modifying the related code in the afterburner module to keep the consistent behavior, or rollback the previous change #3486 (and subsequent changes if possible) to revert to the original but consistent behavior.The text was updated successfully, but these errors were encountered: