Add two JsonGetter examples

This commit is contained in:
Alex Theedom
2017-01-31 06:40:13 +00:00
parent e02f7825a3
commit 5bd907aa01
3 changed files with 61 additions and 4 deletions
@@ -0,0 +1,33 @@
package com.baeldung.jacksonannotation.serialization.jsongetter;
import com.baeldung.jacksonannotation.domain.Item;
import com.baeldung.jacksonannotation.domain.Person;
import com.fasterxml.jackson.annotation.JsonGetter;
import java.util.ArrayList;
import java.util.List;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
public class Author1 extends Person {
List<Item> items = new ArrayList<>();
public Author1(String firstName, String lastName) {
super(firstName, lastName);
}
@JsonGetter
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
}
@@ -14,11 +14,11 @@ import java.util.List;
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
public class Author extends Person {
public class Author2 extends Person {
List<Item> items = new ArrayList<>();
public Author(String firstName, String lastName) {
public Author2(String firstName, String lastName) {
super(firstName, lastName);
}
@@ -27,6 +27,7 @@ public class Author extends Person {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}