Difference between revisions of "Jackson examples"
From DarkWiki
(Created page with "===Interface members=== <source lang="java"> package andy.jackson.demo.model.impl; import andy.jackson.demo.model.Person; import com.fasterxml.jackson.databind.annotation.Js...") |
(→Interface members) |
||
| Line 11: | Line 11: | ||
public class FamilyImpl implements andy.jackson.demo.model.Family { | public class FamilyImpl implements andy.jackson.demo.model.Family { | ||
| + | /* | ||
| + | As the interface (andy.jackson.demo.model.Family) requires we emit a List of andy.jackson.demo.model.Person (another interface), we | ||
| + | make use the JsonDeserialize annotation to tell Jackson to create the list using the PersonImpl concrete implementation class. | ||
| + | */ | ||
@JsonDeserialize(as=List.class,contentAs=PersonImpl.class) | @JsonDeserialize(as=List.class,contentAs=PersonImpl.class) | ||
private List<Person> people = new ArrayList<>(); | private List<Person> people = new ArrayList<>(); | ||
Revision as of 13:11, 7 February 2018
Interface members
package andy.jackson.demo.model.impl;
import andy.jackson.demo.model.Person;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.util.ArrayList;
import java.util.List;
public class FamilyImpl implements andy.jackson.demo.model.Family {
/*
As the interface (andy.jackson.demo.model.Family) requires we emit a List of andy.jackson.demo.model.Person (another interface), we
make use the JsonDeserialize annotation to tell Jackson to create the list using the PersonImpl concrete implementation class.
*/
@JsonDeserialize(as=List.class,contentAs=PersonImpl.class)
private List<Person> people = new ArrayList<>();
private String surname;
@Override
public List<Person> getPeople() {
return people;
}
public void setPeople(List<Person> people) {
this.people = people;
}
@Override
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
}