users@jsonb-spec.java.net

[jsonb-spec users] Re: How is Double.NaN marshalled?

From: Arend v. Reinersdorff <arend_at_arendvr.com>
Date: Sat, 12 Sep 2015 09:09:02 +0200

Hi Dmitry,

thanks a lot for the clarification. Serializing the special double values
as strings makes sense.

It would be nice if this could be stated more explicitly in the JSONB spec.
I think at the moment section 3.17 doesn't really include NaN. Not-A-Numer
doesn't "express greater magnitude or precision than an IEEE 754 double
precision numbers".

Best regards,
Arend


On Fri, Sep 11, 2015 at 2:28 PM, Dmitry Kornilov <dmitry.kornilov_at_oracle.com
> wrote:

> Hi Arend,
>
> It says in the spec that serialization/deserialization must follow the
> conversion process defined in javadoc for toString/parse methods. NaN
> handling is described there.
>
> Here is a link to javadoc:
> http://docs.oracle.com/javase/8/docs/api/java/lang/Double.html
>
> JSONB 3.16 says that "JSON Binding implementation MUST serialize numbers
> that express greater magnitude or precision than an IEEE 754 double
> precision number as strings".
>
> It means that Double.NaN will be serialized to "NaN" string and vise
> versa. "NaN" and "Infinity" are actually strings here (in double quotes)
> which makes it compatible with JSON spec.
>
> Double d = Double.NaN; -> { d: "NaN" }
>
> But I agree that JSONB spec has to be more clear in this case.
>
> Best regards,
> Dmitry Kornilov
>
>
> On 10.9.2015 21:54, Arend v. Reinersdorff wrote:
>
>> Hi,
>>
>> issue JSONB_SPEC-9 mentions that NaN needs to be handled as a special
>> case:
>> https://java.net/jira/browse/JSONB_SPEC-9
>>
>> But I didn't find this case in the spec draft. I looked in section 3.3.2
>> "java.lang.Byte, Short, Integer, Long, Float, Double".
>>
>> JSON doesn't allow NaN or Infinity as number values. So I think these
>> cases need special handling when marshalling a float or double?
>>
>> Best regards,
>> Arend
>>
>>
>