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

configureAbsentsAsNulls not working for primitive Optionals like OptionalInt #13

Closed
lrpg opened this issue Feb 28, 2017 · 4 comments
Closed
Milestone

Comments

@lrpg
Copy link

lrpg commented Feb 28, 2017

type.isTypeOrSubTypeOf(Optional.class)

is evaluated to true with Optional<Integer> while
it is evaluated to false with OptionalInt because OptionalInt is not a type or subtype of Optional<>

Same goes for OptionalDouble and OptionalLong

https://github.com/FasterXML/jackson-modules-java8/blob/master/datatypes/src/main/java/com/fasterxml/jackson/datatype/jdk8/Jdk8BeanSerializerModifier.java#L26

@cowtowncoder
Copy link
Member

What is the bug here? Optionalnt is indeed not a sub-type of Optional in Java world. You may think of them as related, but from Java (JVM) type system perspective they are not related.

But perhaps you have an actual problem, and above is just explaining why you think that might occur? If so, please describe the problem first.

@lrpg
Copy link
Author

lrpg commented Mar 1, 2017

Jdk8Module.configureAbsentsAsNulls has an effect on Optional<> but not OptionalInt, OptionalLong and OptionalDouble, which is confusing and contradictory according to the javadoc of the Jdk8Module.configureAbsentsAsNulls:
Configuration setting that determines whether Optional.empty() is considered "same as null" for serialization purposes; that is, to be filtered same as nulls are. If enabled, absent values are treated like nulls; if disabled, they are not. In either case, absent values are always considered "empty".

The logic around Optional happens in Jdk8BeanSerializerModifier at type.isTypeOrSubTypeOf(Optional.class) as specified above.

@cowtowncoder cowtowncoder changed the title Jdk8BeanSerializerModifier behaves differently with Optional<T> and primitive Optionals like OptionalInt configureAbsentsAsNulls not working for primitive Optionals like OptionalInt Mar 1, 2017
@cowtowncoder
Copy link
Member

@lrpg thank you for clarification, makes sense. I updated title to reflect what I think is the issue.

@cowtowncoder cowtowncoder added this to the 2.9.0.pr2 milestone Mar 15, 2017
@cowtowncoder
Copy link
Member

Ok required bit bigger changes but works now, for 2.9.0(.pr2).

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

2 participants