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
Just like in #237, I also like to stick to immutable pojos. However I tried a different approach using Optional<> fields. In comparisons like this on with other Json serialization frameworks (Jackson and/or Gson) it is stated that JSON-B has improved handling of Optional<> fields.
However the examples mostly show only serialization works. How about deserialization optional fields. Especially when using immutable pojos. In the following example I used a contructor with Optional<> arguments:
Json: {"mandatory":"mandatory"}
Jun 24, 2019 11:29:14 PM org.eclipse.yasson.internal.Unmarshaller deserializeItem
SEVERE: JsonbCreator parameter optional is missing in json document.
Exception in thread "main" javax.json.bind.JsonbException: JsonbCreator parameter optional is missing in json document.
at org.eclipse.yasson.internal.serializer.ObjectDeserializer.createInstance(ObjectDeserializer.java:120)
at org.eclipse.yasson.internal.serializer.ObjectDeserializer.getInstance(ObjectDeserializer.java:93)
at org.eclipse.yasson.internal.serializer.AbstractContainerDeserializer.deserialize(AbstractContainerDeserializer.java:61)
at org.eclipse.yasson.internal.Unmarshaller.deserializeItem(Unmarshaller.java:70)
at org.eclipse.yasson.internal.Unmarshaller.deserialize(Unmarshaller.java:56)
at org.eclipse.yasson.internal.JsonBinding.deserialize(JsonBinding.java:53)
at org.eclipse.yasson.internal.JsonBinding.fromJson(JsonBinding.java:60)
at OptionalInConstructor.main(OptionalInConstructor.java:39)
When the Optional<> argument is present it works correctly.
Should this be possible? Or is there another way (without making my pojo mutable) to achieve this?
The text was updated successfully, but these errors were encountered:
misl
changed the title
Can not use Optional<> arguments in @JsonbCreator method/constructor
Can not copy with Optional.empty() arguments in @JsonbCreator method/constructor
Jun 25, 2019
misl
changed the title
Can not copy with Optional.empty() arguments in @JsonbCreator method/constructor
Can not cope with Optional.empty() arguments in @JsonbCreator method/constructor
Jun 25, 2019
Just like in #237, I also like to stick to immutable pojos. However I tried a different approach using
Optional<>
fields. In comparisons like this on with other Json serialization frameworks (Jackson and/or Gson) it is stated that JSON-B has improved handling ofOptional<>
fields.However the examples mostly show only serialization works. How about deserialization optional fields. Especially when using immutable pojos. In the following example I used a contructor with
Optional<>
arguments:Unfortunately this lead to the following error:
When the
Optional<>
argument is present it works correctly.Should this be possible? Or is there another way (without making my pojo mutable) to achieve this?
The text was updated successfully, but these errors were encountered: