in stetho/src/main/java/com/facebook/stetho/json/ObjectMapper.java [271:303]
private Object getJsonValue(Object value, Class<?> clazz, Field field)
throws InvocationTargetException, IllegalAccessException {
if (value == null) {
// Now technically we /could/ return JsonNode.NULL here but Chrome's webkit inspector croaks
// if you pass a null "id"
return null;
}
if (List.class.isAssignableFrom(clazz)) {
return convertListToJsonArray(value);
}
// Finally check to see if there is a JsonValue present
Method m = getJsonValueMethod(clazz);
if (m != null) {
return m.invoke(value);
}
if (!canDirectlySerializeClass(clazz)) {
return convertValue(value, JSONObject.class);
}
// JSON has no support for NaN, Infinity or -Infinity, so we serialize
// then as strings. Google Chrome's inspector will accept them just fine.
if (clazz.equals(Double.class) || clazz.equals(Float.class)) {
double doubleValue = ((Number) value).doubleValue();
if (Double.isNaN(doubleValue)) {
return "NaN";
} else if (doubleValue == Double.POSITIVE_INFINITY) {
return "Infinity";
} else if (doubleValue == Double.NEGATIVE_INFINITY) {
return "-Infinity";
}
}
// hmm we should be able to directly serialize here...
return value;
}