Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 639 by
kaspar....@gmail.com: Serialization of NaN/Inf with
complex map key serialization and special floating point values enabled is
broken
https://code.google.com/p/google-gson/issues/detail?id=639
What steps will reproduce the problem?
1. Run the following code snippet:
Map map = new HashMap();
map.put(Double.NaN, "x");
System.out.println(new GsonBuilder()
.enableComplexMapKeySerialization()
.serializeSpecialFloatingPointValues()
.create()
.toJson(map));
What is the expected output? What do you see instead?
Expected:
{"NaN":"x"}
Actual:
Exception in thread "main" java.lang.IllegalArgumentException: JSON forbids
NaN and infinities: NaN
at
com.google.gson.internal.bind.JsonTreeWriter.value(JsonTreeWriter.java:183)
at
com.google.gson.internal.bind.TypeAdapters$10.write(TypeAdapters.java:298)
at
com.google.gson.internal.bind.TypeAdapters$10.write(TypeAdapters.java:287)
at
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
at com.google.gson.TypeAdapter.toJsonTree(TypeAdapter.java:230)
at
com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.write(MapTypeAdapterFactory.java:219)
at
com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.write(MapTypeAdapterFactory.java:145)
at com.google.gson.Gson.toJson(Gson.java:595)
at com.google.gson.Gson.toJson(Gson.java:574)
at com.google.gson.Gson.toJson(Gson.java:529)
at com.google.gson.Gson.toJson(Gson.java:509)
What version of the product are you using? On what operating system?
- Gson 2.3.1
- Windows 7 Enterprise, Servie Pack 1
Please provide any additional information below.
Looks like the complex map key serialization doesn't forward the lenient
flag from the JsonWriter to the JsonTreeWriter, hence the error.
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings