相关文章推荐
坚韧的松鼠  ·  Apache Spark ...·  2 月前    · 
睡不着的双杠  ·  Android ...·  1 年前    · 
坚韧的马克杯  ·  SQL Server ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

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.

You can enable ALLOW_TRAILING_COMMA (allowing a comma after the last value in an object or array), and then it parses it correctly, not having to modify the json and remove the comma:

jsonFactory.configure(JsonReadFeature.ALLOW_TRAILING_COMMA.mappedFeature(), true)
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.