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
What steps will reproduce the problem?
public class GsonDouble
{
private double negInf = Double.NEGATIVE_INFINITY;
private double posInf = Double.POSITIVE_INFINITY;
private double notANumber = Double.NaN;
private double number = 2.0;
public static void main(String[] args)
{
Gson gson = new Gson();
String json = gson.toJson(new GsonDouble());
System.out.println(json);
GsonDouble gsonDouble = gson.fromJson(json, GsonDouble.class);
}
}
Exception in thread "main" com.google.gson.JsonParseException: Failed
parsing JSON source: java.io.StringReader@134bed0 to Json
at com.google.gson.Gson.fromJson(Gson.java:376)
at com.google.gson.Gson.fromJson(Gson.java:321)
at com.google.gson.Gson.fromJson(Gson.java:297)
at GsonDouble.main(GsonDouble.java:29)
Caused by: com.google.gson.TokenMgrError: Lexical error at line 1, column
12. Encountered: "I" (73), after : ""
at
com.google.gson.JsonParserTokenManager.getNextToken(JsonParserTokenManager.java:
999)
at com.google.gson.JsonParser.jj_consume_token(JsonParser.java:366)
at com.google.gson.JsonParser.Digits(JsonParser.java:267)
at com.google.gson.JsonParser.JsonInt(JsonParser.java:241)
at com.google.gson.JsonParser.JsonNumber(JsonParser.java:192)
at com.google.gson.JsonParser.JsonValue(JsonParser.java:131)
at com.google.gson.JsonParser.Pair(JsonParser.java:78)
at com.google.gson.JsonParser.Members(JsonParser.java:61)
at com.google.gson.JsonParser.JsonObject(JsonParser.java:42)
at com.google.gson.JsonParser.parse(JsonParser.java:11)
at com.google.gson.Gson.fromJson(Gson.java:370)
... 3 more
The serialized String looks as follows:
{"negInf":-Infinity,"posInf":Infinity,"notANumber":NaN,"number":2.0}
I guess the serialization is ok, since JavaScript uses Number.NaN,
Number.NEGATIVE_INFINITY and Number.POSITIVE_INFINITY and the text
representation fits the above JSON string.
The deserializer seems to be unaware of this.
I would be great if you could fix this for the upcoming release.
Original issue reported on code.google.com by nit...@googlemail.com on 12 Dec 2008 at 1:09
The text was updated successfully, but these errors were encountered:
@zipswich, what error message do you observe? I see
Caused by: java.lang.IllegalArgumentException: -Infinity is not a valid double value as per JSON specification. To override this behavior, use GsonBuilder.serializeSpecialFloatingPointValues() method.
and when I use
GsonBuilder.serializeSpecialFloatingPointValues()
to create my Gson I can serialize both float and double infinities and NaNs (on version 2.8.5)
Original issue reported on code.google.com by
nit...@googlemail.com
on 12 Dec 2008 at 1:09The text was updated successfully, but these errors were encountered: