all should be strings
Closed this issue · 2 comments
GoogleCodeExporter commented
Version 1.3 does a good job of converting an Object to JSON string
following JSON standards.. However it does not suit my requirement, that
is is all the data should be strings, meaning all the keys and values
should be enclosed by double quotes including for numbers, float, and
integers...
example:
"amount":1.3300000000000000710542735760100185871124267578125 - current
"amount":"1.3300000000000000710542735760100185871124267578125" - needed
How can i achieve this? Can i change the source code to get this behavior?
where do i start? thanks a bunch in advance...
-
Original issue reported on code.google.com by pudur.ra...@gmail.com
on 30 Jul 2009 at 9:31
GoogleCodeExporter commented
You should be able to accomplish this without modifying any of the Gson code,
but
rather creating your own serializers for longs, float, double, etc.
Here is an example of a Long serializer:
public class MyLongSerializer implements JsonSerializer<Long> {
public JsonElement serialize(Long src, Type typeOfSrc, JsonSerializationContext
context) {
return new JsonPrimitive(String.valueOf(src));
}
}
You would then register these custom serializers using the GsonBuilder.
Hope this helps,
Joel
Original comment by joel.leitch@gmail.com
on 18 Aug 2009 at 6:01
GoogleCodeExporter commented
Having Gson output a number as a number and not as a string is a feature not a
bug.
Original comment by inder123
on 23 Sep 2009 at 7:05
- Changed state: WontFix