inorik
inorik

Reputation: 147

Why does jackson-jr not detect dupliacte JSON keys?

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?

Update

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

Answers (1)

inorik
inorik

Reputation: 147

It is a bug and has been fixed in the development branch. It will be included in version 2.8.9 and 2.9.0.pr3.

Upvotes: 2

Related Questions