1
Json serialization, double.NaN management?
Question asked by Jean-Pierre Alvarez - 3/8/2023 at 3:46 PM
Answered
Hello, when I try to serialize an object that contains a double value that is NaN, I get as result a "NaN" in the generated text, no problem with that. But when I try to deserialize this same string I get this exception:

LiquidTechnologies.XmlObjects.LxInvalidStateException: Expected Value '{', '[', '"', '0-9', '-', 'true', 'false' or 'null', found 'N' at line 84, posi...

Is there a way to handle the double.NaN correctly? I haven't found any options to inject to the LjSerializer as it is possible with other json serializers.

Thank you.

[Edit]
I tried to write "null" instead on "NaN" while serializing, but then i get this exception:

LiquidTechnologies.XmlObjects.LxSerializationException: The value of the element VSVMLimit@KWKA_XML_Intake can not be read into property KWKAIntake.DFCt.VSVMLimit. The value '' could not be converted to an xs:XsdDouble

3 Replies

Reply to Thread
1
Liquid Support Replied
Employee Post
Hi, yes you are correct. This works OK in XML as 'NaN', 'INF' and '-INF' are valid floating point values. But this is not the case in JSON.

We will add settings to the LjReaderSettings and LjWriterSettings to enable you to set if these are valid or if an exception should be raised.

This should be available in a few days.
0
Jean-Pierre Alvarez Replied
Thank you for your reactivity.
1
Liquid Support Replied
Employee Post Marked As Answer
This issue has now been fixed and is available in v20.2.6:

Documentation can be found here:

We set the default to true to maintain backwards compatibility.

Reply to Thread