Jackson examples
From DarkWiki
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;
}
}