I have a small sample of test code where I try to convert a Map into a JSON string and back. While parsing from the JSON string, the resulting map contains the String key "1" instead of the Integer key "1", thus making the test fail. The same happens with POJOs used as the key to this map. Is this behaviour expected or have I ommited some configuration for the JSON converters?
public class SampleConverterTest {
@Test
public void testIntegerKey() {
// Register an Integer converter
JSON.registerConvertor(Integer.class, new JSONPojoConvertor(Integer.class));
Map<Integer, String> map = new HashMap<Integer, String>();
map.put(1, "sample");
// Convert to JSON
String msg = JSON.toString(map);
// Retrieve original map from JSON
@SuppressWarnings("unchecked")
Map<Integer, String> obj = (Map<Integer, String>) JSON.parse(msg);
assertTrue(obj.containsKey(1));
}
}
I am using jetty-util 7.6.10.v20130312