Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

json

jackson

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",

    }
]
like image 422
Rollyng Avatar asked Oct 31 '13 14:10

Rollyng


2 Answers

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.

like image 166
eis Avatar answered Nov 18 '22 02:11

eis


It's because your last entries, there is an , after your last value. Thats why jackson expects another field.

like image 40
Martin Seeler Avatar answered Nov 18 '22 04:11

Martin Seeler