The server side successfully generates JSON object for Nan values as I am using serializeSpecialFloatingPointValues()
method. I am getting an error due to Nan on the client side. Is there a option which I can include on the client side to handle Nan similar to the one available on server side in jQuery ?
Server Side
Server side Gson successfully generate JSON object
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.serializeSpecialFloatingPointValues();
Gson gson = gsonBuilder.setPrettyPrinting().create();
String jsonString = gson.toJson(Object, HashMap.class);
response.getWriter().write(jsonString);
response.getWriter().flush();
Output Generated from Server
{
"name": "ABC",
"data1": 511,
"data2": NaN
}
Client Side
$.ajax({
url: "AbcServlet",
data: {
input: abc,
},
dataType: "json",
type: "GET",
async: false,
success: function (parsed_json) {
evaluate(parsed_json);
},
error: function (request, status, error) {
alert("Error " + error);
}
});
Note: Client side works perfectly if Nan in the json response output is replaced by a number.
My question is if com.google.gson.Gson has has the option to handle or generate Nan, there must be some option to handle it on the client side as well.