Skip to content
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

Afterburner Interferes With Options Respecting Include.NON_NULL #226

Closed
omervk opened this issue Sep 29, 2015 · 6 comments
Closed

Afterburner Interferes With Options Respecting Include.NON_NULL #226

omervk opened this issue Sep 29, 2015 · 6 comments
Milestone

Comments

@omervk
Copy link

omervk commented Sep 29, 2015

If Afterburner (jackson-module-afterburner) is registered on an ObjectMapper before DefaultScalaModule, it interferes with (at least) how None is serialized when Include.NON_NULL is in play.

case class A(foo: Option[String] = None)
class B {
    @JsonProperty val foo: Option[String] = None
}

val objectMapper = new ObjectMapper()
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
objectMapper.registerModule(new AfterburnerModule)
objectMapper.registerModule(DefaultScalaModule)

val caseClassJson = objectMapper.writeValueAsString(A())
val objectJson = objectMapper.writeValueAsString(new B())
val anonymousObjectJson = objectMapper.writeValueAsString(new {
    @JsonProperty val foo: Option[String] = None
})

Expected:

caseClassJson == "{}"
objectJson == "{}"
anonymousObjectJson == "{}"

Actual:

caseClassJson == """{ "foo": null }"""
objectJson == """{ "foo": null }"""
anonymousObjectJson == "{}"
@christophercurrie
Copy link
Member

Interesting. Does the order of registering the modules make a difference?

@cowtowncoder
Copy link
Member

Another thing that may be of importance here is that Jackson 2.6 has improved support for "referential" types, aimed at better support for Option/Optionals (and some other similar types like AtomicReference).
There are things module needs to do to take advantage of this, we may need to verify that Scala module does those. This matters mostly because jackson-databind is responsible for much/most of actual serialization exclusion handling.

@christophercurrie JDK8 module and Guava have relevant code, and maybe former is simpler example, on how to resolve option(al) type as ReferenceType, if that is not yet done (I forget whether we talked about this earlier)

@christophercurrie
Copy link
Member

I don't think that the Scala module has yet picked up on that. I'll dig into the JDK8 module's examples as time allows.

@omervk
Copy link
Author

omervk commented Oct 14, 2015

@christophercurrie

Interesting. Does the order of registering the modules make a difference?

Yes, registering Afterburner after the Scala module does not cause this issue. I am not sure whether it might cause issues with Afterburner, though.

@nbauernfeind nbauernfeind added this to the 2.7.4 milestone Apr 25, 2016
@omervk
Copy link
Author

omervk commented Jun 5, 2016

As a side-effect of the 2.7.4 release, the non-standard NON_NULL behavior with respect to Option has been fixed and the correct NON_ABSENT should be used instead. Original issue has also been resolved.

Thanks 👍

@cowtowncoder
Copy link
Member

@omervk Thank you for verifying this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants