Map<String, Object> typed serialization broken for Integer and Date objects
costin3141 opened this issue · comments
I have the following example code:
public static void main( String[] args ) {
final Map<String, Object> map = new HashMap<>();
map.put( "Long", Long.valueOf( 179 ) );
map.put( "Integer", Integer.valueOf( 179 ) );
map.put( "Double", Double.valueOf( 179 ) );
map.put( "date", new Date() );
final Map params = new HashMap();
params.put( JsonWriter.DATE_FORMAT, JsonWriter.ISO_DATE_TIME_FORMAT );
final String str = JsonWriter.objectToJson( map, params );
System.out.println( str + "\n" );
final Map<String, Object> map2 = JsonReader.jsonToMaps( str );
for( Entry<String, Object> entry : map2.entrySet() ) {
System.out.println( entry.getKey() + " : " + entry.getValue() + " | " + entry.getValue().getClass().getSimpleName() );
}
}
which produces the following:
{"@type":"java.util.HashMap","Integer":{"@type":"int","value":179},"date":{"@type":"date","value":"2017-08-16T12:23:18"},"Long":179,"Double":179.0}
Integer : {value=179} | JsonObject
date : {value=2017-08-16T12:23:18} | JsonObject
Long : 179 | Long
Double : 179.0 | Double
As you can see it fails deserializing the Integer object and the Date object. Interesting is that on serialization exactly these two objects have a different style of type information as the other objects. While Long object got type "Long" the Date object got "date" and Integer got "int".
Something seems broken here.
Damn, that formatting here is also broken :(
I will look into this, build tests, fix, and re-release. May take a few days.
This has been fixed, test added, and released in 4.10.0.