final String keyName = "testKey";
final String json = "{ \"" + keyName + "\" : 1 }";
final byte[] jsonAsBytes = json.getBytes(Data.UTF_8_CHARSET);
{
final JsonFactory jsonFactory = new JsonFactory();
final JacksonDataCodec codec = new JacksonDataCodec(jsonFactory);
// make sure intern field names is not enabled
assertFalse(jsonFactory.isEnabled(JsonFactory.Feature.INTERN_FIELD_NAMES));
assertTrue(jsonFactory.isEnabled(JsonFactory.Feature.CANONICALIZE_FIELD_NAMES));
final DataMap map = codec.bytesToMap(jsonAsBytes);
final String key = map.keySet().iterator().next();
assertNotSame(key, keyName);
}
{
final JsonFactory jsonFactory = new JsonFactory();
final JacksonDataCodec codec = new JacksonDataCodec(jsonFactory);
// enable intern field names
jsonFactory.enable(JsonFactory.Feature.INTERN_FIELD_NAMES);
assertTrue(jsonFactory.isEnabled(JsonFactory.Feature.INTERN_FIELD_NAMES));
assertTrue(jsonFactory.isEnabled(JsonFactory.Feature.CANONICALIZE_FIELD_NAMES));
final DataMap map = codec.bytesToMap(jsonAsBytes);
final String key = map.keySet().iterator().next();
assertSame(key, keyName);
}
}