Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Yasson » Null OptionalInt deseralized as null(Deserializing empty OptionalInt attribute not conform to the spec?)
Null OptionalInt deseralized as null [message #1750493] Wed, 21 December 2016 16:42 Go to next message
Jean-Francois James is currently offline Jean-Francois JamesFriend
Messages: 5
Registered: December 2016
Junior Member
I've done a small test with a Person class having an OptionalInt attribute (see attached file).
Serialisation and deserialization are OK with a non empty value.
Seralization is OK with an empty value. But deserialization is not: the field value is null instead of being an empty OptionalInt.
This seems in contradiction with the specification (chapter 3.14.1 related to Null Java field). Is it a bug or do I miss something?
Re: Null OptionalInt deseralized as null [message #1750549 is a reply to message #1750493] Thu, 22 December 2016 13:36 Go to previous messageGo to next message
Ehsan Zaery Moghaddam is currently offline Ehsan Zaery MoghaddamFriend
Messages: 8
Registered: December 2016
Junior Member

Hi Jean-Francois

The second paragraph of chapter 3.14.1 is:

Quote:
The deserialization operation of a property absent in JSON document MUST not set the value of the field, the setter (if available) MUST not be called, and thus original value of the field MUST be preserved.


In your second test, the OptionalInt property doesn't exist on the JSON string, so it's value remains untouched during deserialization process.

Regards
Ehsan
Re: Null OptionalInt deseralized as null [message #1750601 is a reply to message #1750549] Fri, 23 December 2016 08:21 Go to previous messageGo to next message
Jean-Francois James is currently offline Jean-Francois JamesFriend
Messages: 5
Registered: December 2016
Junior Member
Hi Ehsan

Thank you for your relevant answer. It helps me understand the subtelities of the spec.
To force the serialization of the OptionalInt attribute with a null value, I've added a @JsonbProperty(nullable=true) on it.
This time we can see that serialization is compliant with the specification: jsonData={"age":null,"name":"Jack"}.

However, deserialization of the same data leads to a null value instead of an OptionalInt.empty: Person{name=Jack, age=null}.
This seems in contradiction with specification:
Quote:
The deserialization operation of a property with a null value in a JSON document MUST set the value of the field to null value (or call setter with null value if setter is present). The exception is java.util.Optional, OptionalInt OptionalLong, OptionalDouble instances. In this case the value of the field is set to an empty optional value.

Please find attached my changed ready-to-run example.
Re: Null OptionalInt deseralized as null [message #1750617 is a reply to message #1750601] Fri, 23 December 2016 11:19 Go to previous messageGo to next message
Ehsan Zaery Moghaddam is currently offline Ehsan Zaery MoghaddamFriend
Messages: 8
Registered: December 2016
Junior Member

Now It looks like a bug Confused , but I'm not sure. I'll check it and let you know about the result.
Re: Null OptionalInt deseralized as null [message #1750694 is a reply to message #1750617] Sun, 25 December 2016 17:21 Go to previous messageGo to next message
Dmitry Kornilov is currently offline Dmitry KornilovFriend
Messages: 9
Registered: June 2014
Junior Member
Yes, it looks like a bug. Can you add it to our bugs tracker please.
https://github.com/eclipse/yasson/issues
Re: Null OptionalInt deseralized as null [message #1750707 is a reply to message #1750694] Mon, 26 December 2016 21:35 Go to previous messageGo to next message
Jean-Francois James is currently offline Jean-Francois JamesFriend
Messages: 5
Registered: December 2016
Junior Member
You've been faster than me to open the issue guys! Thanks.
Re: Null OptionalInt deseralized as null [message #1755292 is a reply to message #1750707] Thu, 02 March 2017 08:08 Go to previous message
Ehsan Zaery Moghaddam is currently offline Ehsan Zaery MoghaddamFriend
Messages: 8
Registered: December 2016
Junior Member

Hi Jean-Francois

The issue is now fixed and would be available in next build on Eclipse maven repository.
Previous Topic:Pb marshalling Optional<java.util.Date> attribute
Next Topic:How thread safe is a Jsonb instance?
Goto Forum:
  


Current Time: Fri Apr 19 17:10:30 GMT 2024

Powered by FUDForum. Page generated in 0.02494 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top