Programmers learn & share
0 votes
1.6k views

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
by (6.9k points)   | 1.6k views

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:

https://github.com/Netflix/conductor/issues/517

by (36.1k points)  
edited by
2,183 questions
2,484 answers
59 comments
241 users