Merge pull request #6452 from amit2103/BAEL-12185
[BAEL-12185] - Updated JACKSON ANNOTATIONS article
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
package com.baeldung.jackson.deserialization.jacksoninject;
|
||||
|
||||
import com.baeldung.jackson.domain.Item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Author extends Person {
|
||||
|
||||
List<Item> items = new ArrayList<>();
|
||||
|
||||
public Author() {
|
||||
}
|
||||
|
||||
public Author(String firstName, String lastName) {
|
||||
super(firstName, lastName);
|
||||
}
|
||||
|
||||
public List<Item> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<Item> items) {
|
||||
this.items = items;
|
||||
}
|
||||
}
|
||||
+2
-12
@@ -1,24 +1,14 @@
|
||||
package com.baeldung.jackson.deserialization.jsonanysetter;
|
||||
|
||||
import com.baeldung.jackson.domain.Author;
|
||||
import com.baeldung.jackson.domain.Item;
|
||||
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
|
||||
public class Inventory {
|
||||
|
||||
private Map<Author, Item> stock = new HashMap<>();
|
||||
|
||||
private Map<String, Float> countryDeliveryCost = new HashMap<>();
|
||||
|
||||
@JsonIgnore
|
||||
public Map<Author, Item> getStock() {
|
||||
return stock;
|
||||
}
|
||||
|
||||
public Map<String, Float> getCountryDeliveryCost() {
|
||||
return countryDeliveryCost;
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.baeldung.jackson.deserialization.jsoncreator;
|
||||
|
||||
import com.baeldung.jackson.domain.Person;
|
||||
import com.baeldung.jackson.domain.Item;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Author extends Person {
|
||||
|
||||
List<Item> items = new ArrayList<>();
|
||||
|
||||
@JsonCreator
|
||||
public Author(@JsonProperty("christianName") String firstName, @JsonProperty("surname") String lastName) {
|
||||
super(firstName, lastName);
|
||||
}
|
||||
|
||||
public List<Item> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<Item> items) {
|
||||
this.items = items;
|
||||
}
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package com.baeldung.jackson.deserialization.jsondeserialize;
|
||||
|
||||
import com.baeldung.jackson.domain.Item;
|
||||
import com.baeldung.jackson.domain.Person;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Author extends Person {
|
||||
|
||||
List<Item> items = new ArrayList<>();
|
||||
|
||||
public Author(String firstName, String lastName) {
|
||||
super(firstName, lastName);
|
||||
}
|
||||
|
||||
public List<Item> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<Item> items) {
|
||||
this.items = items;
|
||||
}
|
||||
}
|
||||
+34
-5
@@ -1,12 +1,16 @@
|
||||
package com.baeldung.jackson.deserialization.jsondeserialize;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Book extends Item {
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
|
||||
public class Book {
|
||||
|
||||
private UUID id;
|
||||
private String title;
|
||||
private float price;
|
||||
private String ISBN;
|
||||
|
||||
@JsonDeserialize(using = CustomDateDeserializer.class)
|
||||
@@ -16,8 +20,9 @@ public class Book extends Item {
|
||||
public Book() {
|
||||
}
|
||||
|
||||
public Book(String title, Author author) {
|
||||
super(title, author);
|
||||
public Book(String title) {
|
||||
this.id = UUID.randomUUID();
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getISBN() {
|
||||
@@ -43,4 +48,28 @@ public class Book extends Item {
|
||||
public void setPages(BigDecimal pages) {
|
||||
this.pages = pages;
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public float getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(float price) {
|
||||
this.price = price;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
package com.baeldung.jackson.deserialization.jsondeserialize;
|
||||
|
||||
import com.baeldung.jackson.domain.Person;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Item {
|
||||
|
||||
private UUID id;
|
||||
private String title;
|
||||
private List<Person> authors = new ArrayList<>();
|
||||
private float price;
|
||||
|
||||
public Item() {
|
||||
}
|
||||
|
||||
public Item(String title, Author author) {
|
||||
this.id = UUID.randomUUID();
|
||||
this.title = title;
|
||||
this.authors.add(author);
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public List<Person> getAuthors() {
|
||||
return authors;
|
||||
}
|
||||
|
||||
public void setAuthors(List<Person> authors) {
|
||||
this.authors = authors;
|
||||
}
|
||||
|
||||
public float getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(float price) {
|
||||
this.price = price;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.baeldung.jackson.deserialization.jsonsetter;
|
||||
|
||||
import com.baeldung.jackson.domain.Item;
|
||||
import com.baeldung.jackson.domain.Person;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonSetter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Author extends Person {
|
||||
|
||||
private List<Item> items = new ArrayList<>();
|
||||
|
||||
public Author() {
|
||||
}
|
||||
|
||||
public Author(String firstName, String lastName) {
|
||||
super(firstName, lastName);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public List<Item> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
@JsonSetter("publications")
|
||||
public void setItems(List<Item> items) {
|
||||
this.items = items;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.baeldung.jackson.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Author extends Person {
|
||||
|
||||
private List<Item> items = new ArrayList<>();
|
||||
|
||||
public Author(String firstName, String lastName) {
|
||||
super(firstName, lastName);
|
||||
}
|
||||
|
||||
public List<Item> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<Item> items) {
|
||||
this.items = items;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package com.baeldung.jackson.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Book extends Item {
|
||||
|
||||
private String ISBN;
|
||||
private Date published;
|
||||
private BigDecimal pages;
|
||||
|
||||
public Book() {
|
||||
}
|
||||
|
||||
public Book(String title, Author author) {
|
||||
super(title, author);
|
||||
}
|
||||
|
||||
public String getISBN() {
|
||||
return ISBN;
|
||||
}
|
||||
|
||||
public void setISBN(String ISBN) {
|
||||
this.ISBN = ISBN;
|
||||
}
|
||||
|
||||
public Date getPublished() {
|
||||
return published;
|
||||
}
|
||||
|
||||
public void setPublished(Date published) {
|
||||
this.published = published;
|
||||
}
|
||||
|
||||
public BigDecimal getPages() {
|
||||
return pages;
|
||||
}
|
||||
|
||||
public void setPages(BigDecimal pages) {
|
||||
this.pages = pages;
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package com.baeldung.jackson.domain;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Course extends Item {
|
||||
|
||||
public enum Medium {
|
||||
CLASSROOM, ONLINE
|
||||
}
|
||||
|
||||
public enum Level {
|
||||
BEGINNER("Beginner", 1), INTERMEDIATE("Intermediate", 2), ADVANCED("Advanced", 3);
|
||||
|
||||
private String name;
|
||||
private int number;
|
||||
|
||||
Level(String name, int number) {
|
||||
this.name = name;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
private float duration;
|
||||
private Medium medium;
|
||||
private Level level;
|
||||
private List<Course> prerequisite;
|
||||
|
||||
public Course(String title, Author author) {
|
||||
super(title, author);
|
||||
}
|
||||
|
||||
public float getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public void setDuration(float duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public Medium getMedium() {
|
||||
return medium;
|
||||
}
|
||||
|
||||
public void setMedium(Medium medium) {
|
||||
this.medium = medium;
|
||||
}
|
||||
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(Level level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public List<Course> getPrerequisite() {
|
||||
return prerequisite;
|
||||
}
|
||||
|
||||
public void setPrerequisite(List<Course> prerequisite) {
|
||||
this.prerequisite = prerequisite;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.baeldung.jackson.domain;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Customer extends Person {
|
||||
|
||||
private String configuration;
|
||||
|
||||
public Customer(String firstName, String lastName) {
|
||||
super(firstName, lastName);
|
||||
}
|
||||
|
||||
public String getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public void setConfiguration(String configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.baeldung.jackson.domain;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Inventory {
|
||||
|
||||
private Map<Author, Item> stock;
|
||||
|
||||
private Map<String, Float> countryDeliveryCost = new HashMap<>();
|
||||
|
||||
public Map<Author, Item> getStock() {
|
||||
return stock;
|
||||
}
|
||||
|
||||
public void setStock(Map<Author, Item> stock) {
|
||||
this.stock = stock;
|
||||
}
|
||||
|
||||
public Map<String, Float> getCountryDeliveryCost() {
|
||||
return countryDeliveryCost;
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package com.baeldung.jackson.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Item {
|
||||
|
||||
private UUID id;
|
||||
private String title;
|
||||
private List<Person> authors = new ArrayList<>();
|
||||
private float price;
|
||||
|
||||
public Item() {
|
||||
}
|
||||
|
||||
public Item(String title, Author author) {
|
||||
this.id = UUID.randomUUID();
|
||||
this.title = title;
|
||||
this.authors.add(author);
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public List<Person> getAuthors() {
|
||||
return authors;
|
||||
}
|
||||
|
||||
public void setAuthors(List<Person> authors) {
|
||||
this.authors = authors;
|
||||
}
|
||||
|
||||
public float getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(float price) {
|
||||
this.price = price;
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package com.baeldung.jackson.domain;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Order {
|
||||
|
||||
private UUID id;
|
||||
private Type type;
|
||||
private int internalAudit;
|
||||
|
||||
public static class Type {
|
||||
public long id;
|
||||
public String name;
|
||||
}
|
||||
|
||||
public Order() {
|
||||
this.id = UUID.randomUUID();
|
||||
}
|
||||
|
||||
public Order(Type type) {
|
||||
this();
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Order(int internalAudit) {
|
||||
this();
|
||||
this.type = new Type();
|
||||
this.type.id = 20;
|
||||
this.type.name = "Order";
|
||||
this.internalAudit = internalAudit;
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,12 @@
|
||||
package com.baeldung.jackson.domain;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Person {
|
||||
|
||||
private UUID id;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
|
||||
public Person() {
|
||||
}
|
||||
|
||||
|
||||
public Person(String firstName, String lastName) {
|
||||
this.id = UUID.randomUUID();
|
||||
super();
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
@@ -38,8 +26,5 @@ public class Person {
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
package com.baeldung.jackson.inclusion.jsonautodetect;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
|
||||
public class Order {
|
||||
|
||||
private UUID id;
|
||||
private Type type;
|
||||
private int internalAudit;
|
||||
|
||||
public static class Type {
|
||||
public long id;
|
||||
public String name;
|
||||
}
|
||||
|
||||
public Order() {
|
||||
this.id = UUID.randomUUID();
|
||||
}
|
||||
|
||||
public Order(Type type) {
|
||||
this();
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Order(int internalAudit) {
|
||||
this();
|
||||
this.type = new Type();
|
||||
this.type.id = 20;
|
||||
this.type.name = "Order";
|
||||
this.internalAudit = internalAudit;
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.baeldung.jackson.inclusion.jsonignore;
|
||||
|
||||
import com.baeldung.jackson.domain.Item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Author extends Person {
|
||||
|
||||
private List<Item> items = new ArrayList<>();
|
||||
|
||||
public Author(String firstName, String lastName) {
|
||||
super(firstName, lastName);
|
||||
}
|
||||
|
||||
public List<Item> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<Item> items) {
|
||||
this.items = items;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package com.baeldung.jackson.inclusion.jsonignore;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Person {
|
||||
|
||||
@JsonIgnore
|
||||
private UUID id;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
|
||||
public Person() {
|
||||
}
|
||||
|
||||
public Person(String firstName, String lastName) {
|
||||
this.id = UUID.randomUUID();
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package com.baeldung.jackson.inclusion.jsonignoreproperties;
|
||||
|
||||
import com.baeldung.jackson.domain.Author;
|
||||
import com.baeldung.jackson.domain.Item;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
@JsonIgnoreProperties({ "medium" })
|
||||
public class Course extends Item {
|
||||
|
||||
public enum Medium {
|
||||
CLASSROOM, ONLINE
|
||||
}
|
||||
|
||||
public enum Level {
|
||||
BEGINNER("Beginner", 1), INTERMEDIATE("Intermediate", 2), ADVANCED("Advanced", 3);
|
||||
|
||||
private String name;
|
||||
private int number;
|
||||
|
||||
Level(String name, int number) {
|
||||
this.name = name;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
private float duration;
|
||||
private Medium medium;
|
||||
private Level level;
|
||||
private List<Course> prerequisite;
|
||||
|
||||
public Course(String title, Author author) {
|
||||
super(title, author);
|
||||
}
|
||||
|
||||
public float getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public void setDuration(float duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public Medium getMedium() {
|
||||
return medium;
|
||||
}
|
||||
|
||||
public void setMedium(Medium medium) {
|
||||
this.medium = medium;
|
||||
}
|
||||
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(Level level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public List<Course> getPrerequisite() {
|
||||
return prerequisite;
|
||||
}
|
||||
|
||||
public void setPrerequisite(List<Course> prerequisite) {
|
||||
this.prerequisite = prerequisite;
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.baeldung.jackson.inclusion.jsonignoretype;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreType;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Order {
|
||||
|
||||
private UUID id;
|
||||
private Type type;
|
||||
|
||||
@JsonIgnoreType
|
||||
public static class Type {
|
||||
public long id;
|
||||
public String name;
|
||||
}
|
||||
|
||||
public Order() {
|
||||
this.id = UUID.randomUUID();
|
||||
}
|
||||
|
||||
public Order(Type type) {
|
||||
this();
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.baeldung.jackson.inclusion.jsoninclude;
|
||||
|
||||
import com.baeldung.jackson.domain.Person;
|
||||
import com.baeldung.jackson.domain.Item;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
@JsonInclude(NON_NULL)
|
||||
public class Author extends Person {
|
||||
|
||||
private List<Item> items = new ArrayList<>();
|
||||
|
||||
public Author(String firstName, String lastName) {
|
||||
super(firstName, lastName);
|
||||
}
|
||||
|
||||
public List<Item> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<Item> items) {
|
||||
this.items = items;
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
package com.baeldung.jackson.miscellaneous.custom;
|
||||
|
||||
import com.baeldung.jackson.domain.Author;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
@CustomCourseAnnotation
|
||||
public class Course extends Item {
|
||||
|
||||
public enum Medium {
|
||||
CLASSROOM, ONLINE
|
||||
}
|
||||
|
||||
public enum Level {
|
||||
BEGINNER("Beginner", 1), INTERMEDIATE("Intermediate", 2), ADVANCED("Advanced", 3);
|
||||
|
||||
private String name;
|
||||
private int number;
|
||||
|
||||
Level(String name, int number) {
|
||||
this.name = name;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
private float duration;
|
||||
private Medium medium;
|
||||
private Level level;
|
||||
private List<Course> prerequisite;
|
||||
|
||||
public Course(String title, Author author) {
|
||||
super(title, author);
|
||||
}
|
||||
|
||||
public float getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public void setDuration(float duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public Medium getMedium() {
|
||||
return medium;
|
||||
}
|
||||
|
||||
public void setMedium(Medium medium) {
|
||||
this.medium = medium;
|
||||
}
|
||||
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(Level level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public List<Course> getPrerequisite() {
|
||||
return prerequisite;
|
||||
}
|
||||
|
||||
public void setPrerequisite(List<Course> prerequisite) {
|
||||
this.prerequisite = prerequisite;
|
||||
}
|
||||
}
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
package com.baeldung.jackson.miscellaneous.custom;
|
||||
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@JacksonAnnotationsInside
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder({ "title", "price", "id", "duration", "authors", "level" })
|
||||
@JsonIgnoreProperties({ "prerequisite" })
|
||||
public @interface CustomCourseAnnotation {
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package com.baeldung.jackson.miscellaneous.custom;
|
||||
|
||||
import com.baeldung.jackson.domain.Author;
|
||||
import com.baeldung.jackson.domain.Person;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Item {
|
||||
|
||||
private UUID id;
|
||||
private String title;
|
||||
private List<Person> authors = new ArrayList<>();
|
||||
private float price;
|
||||
|
||||
public Item() {
|
||||
}
|
||||
|
||||
public Item(String title, Author author) {
|
||||
this.id = UUID.randomUUID();
|
||||
this.title = title;
|
||||
this.authors.add(author);
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public List<Person> getAuthors() {
|
||||
return authors;
|
||||
}
|
||||
|
||||
public void setAuthors(List<Person> authors) {
|
||||
this.authors = authors;
|
||||
}
|
||||
|
||||
public float getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(float price) {
|
||||
this.price = price;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package com.baeldung.jackson.miscellaneous.disable;
|
||||
|
||||
import com.baeldung.jackson.domain.Item;
|
||||
import com.baeldung.jackson.domain.Person;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder({ "lastName", "items", "firstName", "id" })
|
||||
public class Author extends Person {
|
||||
|
||||
@JsonIgnore
|
||||
private List<Item> items = new ArrayList<>();
|
||||
|
||||
public Author(String firstName, String lastName) {
|
||||
super(firstName, lastName);
|
||||
}
|
||||
|
||||
public List<Item> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<Item> items) {
|
||||
this.items = items;
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.baeldung.jackson.miscellaneous.mixin;
|
||||
|
||||
import com.baeldung.jackson.domain.Item;
|
||||
import com.baeldung.jackson.domain.Person;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Author extends Person {
|
||||
|
||||
private List<Item> items = new ArrayList<>();
|
||||
|
||||
public Author(String firstName, String lastName) {
|
||||
super(firstName, lastName);
|
||||
}
|
||||
|
||||
public List<Item> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<Item> items) {
|
||||
this.items = items;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.baeldung.jackson.miscellaneous.mixin;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreType;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
@JsonIgnoreType
|
||||
public class IgnoreListMixIn {
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package com.baeldung.jackson.polymorphism;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Order {
|
||||
|
||||
private UUID id;
|
||||
private Type type;
|
||||
private int internalAudit;
|
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "ordertype")
|
||||
@JsonSubTypes({ @JsonSubTypes.Type(value = InternalType.class, name = "internal") })
|
||||
public static class Type {
|
||||
public long id;
|
||||
public String name;
|
||||
}
|
||||
|
||||
@JsonTypeName("internal")
|
||||
public static class InternalType extends Type {
|
||||
public long id;
|
||||
public String name;
|
||||
}
|
||||
|
||||
public Order() {
|
||||
this.id = UUID.randomUUID();
|
||||
}
|
||||
|
||||
public Order(Type type) {
|
||||
this();
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Order(int internalAudit) {
|
||||
this();
|
||||
this.type = new Type();
|
||||
this.type.id = 20;
|
||||
this.type.name = "Order";
|
||||
this.internalAudit = internalAudit;
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.baeldung.jackson.serialization.jsonanygetter;
|
||||
|
||||
import com.baeldung.jackson.domain.Author;
|
||||
import com.baeldung.jackson.domain.Item;
|
||||
import com.fasterxml.jackson.annotation.JsonAnyGetter;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Inventory {
|
||||
|
||||
private String location;
|
||||
|
||||
private Map<Author, Item> stock = new HashMap<>();
|
||||
|
||||
private Map<String, Float> countryDeliveryCost = new HashMap<>();
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Map<Author, Item> getStock() {
|
||||
return stock;
|
||||
}
|
||||
|
||||
@JsonAnyGetter
|
||||
public Map<String, Float> getCountryDeliveryCost() {
|
||||
return countryDeliveryCost;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.baeldung.jackson.serialization.jsongetter;
|
||||
|
||||
import com.baeldung.jackson.domain.Item;
|
||||
import com.baeldung.jackson.domain.Person;
|
||||
import com.fasterxml.jackson.annotation.JsonGetter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Source code github.com/readlearncode
|
||||
*
|
||||
* @author Alex Theedom www.readlearncode.com
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Author extends Person {
|
||||
|
||||
List<Item> items = new ArrayList<>();
|
||||
|
||||
public Author(String firstName, String lastName) {
|
||||
super(firstName, lastName);
|
||||
}
|
||||
|
||||
@JsonGetter("publications")
|
||||
public List<Item> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<Item> items) {
|
||||
this.items = items;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user