Search code examples
javajsonjackson

Jackson Error Unexpected character ('}' (code 125))


Hey i got an issue based on deserialization with jackson, here what i've tried and the error i got.

ERROR : com.fasterxml.jackson.core.JsonParseException: Unexpected character ('}' (code 125)): was expecting double-quote to start field name

Java Code

List<Contact> ds = mapper.readValue(data, mapper.getTypeFactory().constructCollectionType(List.class, Contact.class));

 //OR this one

List<Contact> ds = mapper.readValue(data, new TypeReference<List<Contact>>() {});

My JSON

[   
    {
        "id": "200",
        "name": "Alexia Milano",
        "email": "[email protected]",
        "prenom": "xx-xx-xxxx,x - street, x - country",

    }, {
        "id": "201",
        "name": "Johnny Depp",
        "email": "[email protected]",
        "prenom": "xx-xx-xxxx,x - street, x - country",

    }
]

Solution

  • If you use json validator, you can see more detailed error message:

    Parse error on line 6:
    ...ntry",            },    {        "id
    ---------------------^
    Expecting 'STRING'
    

    you have extra comma there after "xx-xx-xxxx,x - street, x - country". If you remove it from both two places, you have valid JSON and Jackson parsing works.