Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Structure validation: duplicate key #37

Copy link
Copy link
@GeTOUO

Description

@GeTOUO
Issue body actions

If there are duplicate keys in the JSON, the current JSON parser will take the value corresponding to the first occurrence of the key:

inputString:

public class SimdJsonTest {

    static final SimdJsonParser SIMD_PARSER = new SimdJsonParser();
    static final ObjectMapper JACKSON = new ObjectMapper();
    static final Gson GSON = new GsonBuilder().create();

    public static void main(String[] args) throws IOException {

        String json = "{\"num\": 2, \"num\": 123}";
        byte[] bytes = json.getBytes();
        JsonValue value = SIMD_PARSER.parse(bytes, bytes.length);

        System.err.println("[simd].size = " + value.getSize());   // 2
        System.err.println("[simd].num = " + value.get("num"));  // 2

        Map jcsObj = JACKSON.readValue(bytes, Map.class);
        System.err.println("[jackson].size = " + jcsObj.size());   // 1
        System.err.println("[jackson].num = " + jcsObj.get("num"));   // 123

        // will throw exception: com.google.gson.JsonSyntaxException: duplicate key: num
        Map gsonObj = GSON.fromJson(new String(bytes), Map.class);
        System.err.println("[gson].size = " + gsonObj.size());
        System.err.println("[gson].num = " + gsonObj.get("num"));
    }
}

The content of the console output:

[simd].size = 2
[simd].num = 2
[jackson].size = 1
[jackson].num = 123
Exception in thread "main" com.google.gson.JsonSyntaxException: duplicate key: num
...

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.