Reputation: 147
I am experimenting with jackson-jr as a lightweight alternative to jackson-databind. My goal is to parse a JSON string and have the parser fail if it encountres a duplicate key. As I understand the library, the following could should throw an exception:
String duplicateKeyString =
"{\"a\":1," +
"\"b\":2," +
"\"b\":3," + // <-- duplicate key
"\"c\":4}";
Map<Object, Object> json = JSON.std.with(JSON.Feature.FAIL_ON_DUPLICATE_MAP_KEYS)
.mapFrom(duplicateKeyString);
For comparison, if I try something similar with jackson-databind, I get the expected IOException:
ObjectMapper om = new ObjectMapper();
om.enable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION);
JsonNode node = om.readTree(duplicateKeyString);
The only difference I can spot is the use of .mapFrom()
and .readTree()
. However, I would still expect the exception to be thrown in both cases. Am I missing something or is this just a bug?
The more similar call
JSON.std.with(new JacksonJrsTreeCodec())
.with(JSON.Feature.FAIL_ON_DUPLICATE_MAP_KEYS)
.treeFrom(duplicateKeyString);
does not throw an Exception either.
Upvotes: 0
Views: 256