Reputation: 403
I receive the following JSON:
{"firstName":"charle","lastName":"charly","books":[{"title":"navle"}]}
And i try to parse it into this Jackson object:
@JsonIgnoreProperties(ignoreUnknown = true)
public class Person {
@Id @ObjectId
private String _id;
private String firstName;
private String lastName;
List<Book> books;
// getters/setters ..
}
The problem is that the Object "Person" that i get have always an empty list of books !
What i'm missing ?
Upvotes: 1
Views: 2933
Reputation: 403
The attribut "title" of the book should be public or you must annotate his getter like this:
@JsonProperty("title")
public String getTitle() {
return title;
}
Upvotes: 1
Reputation: 14286
Make the list of books public, Jackson will serialize only "visible" properties. Plus Book properties must be public.
public List<Book> books;
or better create a getter
@JsonProperty("books")
public List<Books> getBooks() {
return books;
}
Upvotes: 0