Reputation: 2750
I am having difficulties transforming a Json String into an Object in java using Jackson.
Model
public class MyList {
public List<MyObj> ads;
}
public class MyObj {
public String id_ad;
}
Data:
String con = "{\"ads\":[{\"id_ad\":\"20439\"}, {\"id_ad\":\"20449\"}]";
Retrieve code:
ObjectMapper objectMapper = new ObjectMapper();
MyList annonces = objectMapper.readValue(con, MyList.class);
Error:
Erreur dans getAllAds: com.fasterxml.jackson.core.io.JsonEOFException:
Unexpected end-of-input: expected close marker for Object (start marker at [Source: {"ads":[{"id_ad":"20439"}, {"id_ad":"20449"}]; line: 1, column: 1])
at [Source: {"ads":[{"id_ad":"20439"}, {"id_ad":"20449"}]; line: 1, column: 91]
Questions:
What is wrong?
Do I need getter/setter for Jackson or public member should work fine?
Upvotes: 0
Views: 664
Reputation: 1678
Your JSON is incorrect, it is missing a closing curly bracket (}
) at the end.
Change from:
String con = "{\"ads\":[{\"id_ad\":\"20439\"}, {\"id_ad\":\"20449\"}]";
to:
String con = "{\"ads\":[{\"id_ad\":\"20439\"}, {\"id_ad\":\"20449\"}]}";
Upvotes: 1