• Register
0 votes

Problem :

I am trying to POST a List of custom objects but i am getting exception as below
can not deserialize instance of java.util.arraylist out of start_object token
6.9k points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

The issue  seems to be the JSON  it is not actually a JSON Array that would look like this:

        "name": "Test order1",
        "detail": "ahk ks"
        "name": "Test order2",
        "detail": "Fisteku"

Since you are not controlling the exact process of deserialization (RestEasy does) 

1) would be to simply inject the JSON as a String and then take control of the deserialization process using bellow code:

Collection<COrder> readValues = new ObjectMapper().readValue(
    jsonAsString, new TypeReference<Collection<COrder>>() { }

You may loose a bit of the convenience of not able to do that yourself, but you would easily sort out the problem.

2)  if you cannot change the JSON - would be to construct a wrapper to fit the structure of your JSON input - and use that instead of Collection<COrder>.

Further Readings:


38.6k points
edited by