[BAEL-16045] - Moved code to java-string-2

This commit is contained in:
amit2103
2019-10-27 19:47:01 +05:30
parent db85c8f275
commit 6bc2f22a9a
20514 changed files with 1642278 additions and 0 deletions
@@ -0,0 +1,32 @@
package com.baeldung.jacksonannotation.deserialization.jacksoninject;
import com.baeldung.jacksonannotation.domain.Item;
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 Author extends Person {
List<Item> items = new ArrayList<>();
public Author(){
super();
}
public Author(String firstName, String lastName) {
super(firstName, lastName);
}
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
}
@@ -0,0 +1,49 @@
package com.baeldung.jacksonannotation.deserialization.jacksoninject;
import com.fasterxml.jackson.annotation.JacksonInject;
import java.util.UUID;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
public class Person {
@JacksonInject
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;
}
}
@@ -0,0 +1,38 @@
package com.baeldung.jacksonannotation.deserialization.jsonanysetter;
import com.baeldung.jacksonannotation.domain.Author;
import com.baeldung.jacksonannotation.domain.Item;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.HashMap;
import java.util.Map;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
* @see JsonAnyGetter
*/
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;
}
@JsonAnySetter
public void addCountryDeliveryCost(String country, Float cost) {
countryDeliveryCost.put(country, cost);
}
}
@@ -0,0 +1,38 @@
package com.baeldung.jacksonannotation.deserialization.jsoncreator;
import com.baeldung.jacksonannotation.domain.Item;
import com.baeldung.jacksonannotation.domain.Person;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.List;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
* @see JsonGetter
*/
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;
}
}
@@ -0,0 +1,30 @@
package com.baeldung.jacksonannotation.deserialization.jsondeserialize;
import com.baeldung.jacksonannotation.domain.Item;
import com.baeldung.jacksonannotation.domain.Person;
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 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;
}
}
@@ -0,0 +1,53 @@
package com.baeldung.jacksonannotation.deserialization.jsondeserialize;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.math.BigDecimal;
import java.util.Date;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
public class Book extends Item {
private String ISBN;
@JsonDeserialize(using = CustomDateDeserializer.class)
private Date published;
private BigDecimal pages;
public Book() {
super();
}
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;
}
}
@@ -0,0 +1,42 @@
package com.baeldung.jacksonannotation.deserialization.jsondeserialize;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
public class CustomDateDeserializer extends StdDeserializer<Date> {
private static SimpleDateFormat formatter =
new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
public CustomDateDeserializer() {
this(null);
}
public CustomDateDeserializer(Class<?> vc) {
super(vc);
}
@Override
public Date deserialize(JsonParser jsonparser, DeserializationContext context)
throws IOException, JsonProcessingException {
String date = jsonparser.getText();
try {
return formatter.parse(date);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
}
@@ -0,0 +1,61 @@
package com.baeldung.jacksonannotation.deserialization.jsondeserialize;
import com.baeldung.jacksonannotation.domain.Person;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,38 @@
package com.baeldung.jacksonannotation.deserialization.jsonsetter;
import com.baeldung.jacksonannotation.domain.Item;
import com.baeldung.jacksonannotation.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/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
public class Author extends Person {
private List<Item> items = new ArrayList<>();
public Author(){
super();
}
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;
}
}
@@ -0,0 +1,27 @@
package com.baeldung.jacksonannotation.domain;
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 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;
}
}
@@ -0,0 +1,48 @@
package com.baeldung.jacksonannotation.domain;
import java.math.BigDecimal;
import java.util.Date;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,71 @@
package com.baeldung.jacksonannotation.domain;
import java.util.List;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,24 @@
package com.baeldung.jacksonannotation.domain;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,29 @@
package com.baeldung.jacksonannotation.domain;
import java.util.HashMap;
import java.util.Map;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,59 @@
package com.baeldung.jacksonannotation.domain;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,50 @@
package com.baeldung.jacksonannotation.domain;
import java.util.UUID;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,44 @@
package com.baeldung.jacksonannotation.domain;
import java.util.UUID;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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();
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;
}
}
@@ -0,0 +1,32 @@
package com.baeldung.jacksonannotation.general.jsonfilter;
import com.baeldung.jacksonannotation.domain.Item;
import com.baeldung.jacksonannotation.domain.Person;
import com.fasterxml.jackson.annotation.JsonFilter;
import java.util.ArrayList;
import java.util.List;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
@JsonFilter("authorFilter")
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;
}
}
@@ -0,0 +1,56 @@
package com.baeldung.jacksonannotation.general.jsonformat;
import com.baeldung.jacksonannotation.domain.Author;
import com.baeldung.jacksonannotation.domain.Item;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.math.BigDecimal;
import java.util.Date;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
public class Book extends Item {
private String ISBN;
@JsonFormat(
shape = JsonFormat.Shape.STRING,
pattern = "dd-MM-yyyy HH:mm:ss")
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;
}
}
@@ -0,0 +1,33 @@
package com.baeldung.jacksonannotation.general.jsonidentityinfo;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import java.util.ArrayList;
import java.util.List;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "id")
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;
}
}
@@ -0,0 +1,72 @@
package com.baeldung.jacksonannotation.general.jsonidentityinfo;
import java.util.List;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,65 @@
package com.baeldung.jacksonannotation.general.jsonidentityinfo;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "id")
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;
}
}
@@ -0,0 +1,44 @@
package com.baeldung.jacksonannotation.general.jsonidentityinfo;
import java.util.UUID;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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();
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;
}
}
@@ -0,0 +1,29 @@
package com.baeldung.jacksonannotation.general.jsonproperty;
import com.baeldung.jacksonannotation.domain.Person;
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 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;
}
}
@@ -0,0 +1,61 @@
package com.baeldung.jacksonannotation.general.jsonproperty;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.math.BigDecimal;
import java.util.Date;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
public class Book extends Item {
private String ISBN;
private Date published;
private BigDecimal pages;
private String binding;
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;
}
@JsonProperty("binding")
public String coverBinding() {
return binding;
}
@JsonProperty("binding")
public void configureBinding(String binding) {
this.binding = binding;
}
}
@@ -0,0 +1,61 @@
package com.baeldung.jacksonannotation.general.jsonproperty;
import com.baeldung.jacksonannotation.domain.Person;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,54 @@
package com.baeldung.jacksonannotation.general.jsonunwrapped;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import java.util.UUID;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
public class Order {
private UUID id;
@JsonUnwrapped
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;
}
}
@@ -0,0 +1,57 @@
package com.baeldung.jacksonannotation.general.jsonview;
import com.fasterxml.jackson.annotation.JsonView;
import java.util.UUID;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
public class Order {
@JsonView(Views.Public.class)
private UUID id;
@JsonView(Views.Public.class)
private Type type;
@JsonView(Views.Internal.class)
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;
}
}
@@ -0,0 +1,15 @@
package com.baeldung.jacksonannotation.general.jsonview;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
public class Views {
public static class Public {
}
public static class Internal extends Public {
}
}
@@ -0,0 +1,30 @@
package com.baeldung.jacksonannotation.general.reference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
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 Author extends Person {
private List<Item> items = new ArrayList<>();
public Author(String firstName, String lastName) {
super(firstName, lastName);
}
@JsonManagedReference
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
}
@@ -0,0 +1,72 @@
package com.baeldung.jacksonannotation.general.reference;
import java.util.List;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,63 @@
package com.baeldung.jacksonannotation.general.reference;
import com.fasterxml.jackson.annotation.JsonBackReference;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
public class Item {
private UUID id;
private String title;
@JsonBackReference
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;
}
}
@@ -0,0 +1,44 @@
package com.baeldung.jacksonannotation.general.reference;
import java.util.UUID;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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();
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;
}
}
@@ -0,0 +1,54 @@
package com.baeldung.jacksonannotation.inclusion.jsonautodetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import java.util.UUID;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,29 @@
package com.baeldung.jacksonannotation.inclusion.jsonignore;
import com.baeldung.jacksonannotation.domain.Item;
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 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;
}
}
@@ -0,0 +1,47 @@
package com.baeldung.jacksonannotation.inclusion.jsonignore;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.UUID;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,76 @@
package com.baeldung.jacksonannotation.inclusion.jsonignoreproperties;
import com.baeldung.jacksonannotation.domain.Author;
import com.baeldung.jacksonannotation.domain.Item;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.List;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,44 @@
package com.baeldung.jacksonannotation.inclusion.jsonignoretype;
import com.fasterxml.jackson.annotation.JsonIgnoreType;
import java.util.UUID;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,34 @@
package com.baeldung.jacksonannotation.inclusion.jsoninclude;
import com.baeldung.jacksonannotation.domain.Item;
import com.baeldung.jacksonannotation.domain.Person;
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/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,74 @@
package com.baeldung.jacksonannotation.miscellaneous.custom;
import com.baeldung.jacksonannotation.domain.Author;
import java.util.List;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,20 @@
package com.baeldung.jacksonannotation.miscellaneous.custom;
import com.fasterxml.jackson.annotation.*;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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 {
}
@@ -0,0 +1,62 @@
package com.baeldung.jacksonannotation.miscellaneous.custom;
import com.baeldung.jacksonannotation.domain.Author;
import com.baeldung.jacksonannotation.domain.Person;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,36 @@
package com.baeldung.jacksonannotation.miscellaneous.disable;
import com.baeldung.jacksonannotation.domain.Item;
import com.baeldung.jacksonannotation.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/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,30 @@
package com.baeldung.jacksonannotation.miscellaneous.mixin;
import com.baeldung.jacksonannotation.domain.Item;
import com.baeldung.jacksonannotation.domain.Person;
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 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;
}
}
@@ -0,0 +1,13 @@
package com.baeldung.jacksonannotation.miscellaneous.mixin;
import com.fasterxml.jackson.annotation.JsonIgnoreType;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
@JsonIgnoreType
public class IgnoreListMixIn {
}
@@ -0,0 +1,66 @@
package com.baeldung.jacksonannotation.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/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,43 @@
package com.baeldung.jacksonannotation.serialization.jsonanygetter;
import com.baeldung.jacksonannotation.domain.Author;
import com.baeldung.jacksonannotation.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/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -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;
}
}
@@ -0,0 +1,34 @@
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 Author2 extends Person {
List<Item> items = new ArrayList<>();
public Author2(String firstName, String lastName) {
super(firstName, lastName);
}
@JsonGetter("publications")
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
}
@@ -0,0 +1,52 @@
package com.baeldung.jacksonannotation.serialization.jsonpropertyorder;
import com.baeldung.jacksonannotation.domain.Item;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import java.util.ArrayList;
import java.util.List;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
@JsonPropertyOrder(value = {"items", "firstName", "lastName", "id"}, alphabetic = true)
public class Author extends Person {
private String zIndex;
private String alphaIndex;
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;
}
public String getzIndex() {
return zIndex;
}
public void setzIndex(String zIndex) {
this.zIndex = zIndex;
}
public String getAlphaIndex() {
return alphaIndex;
}
public void setAlphaIndex(String alphaIndex) {
this.alphaIndex = alphaIndex;
}
}
@@ -0,0 +1,42 @@
package com.baeldung.jacksonannotation.serialization.jsonpropertyorder;
import java.util.UUID;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
public class Person {
private UUID id;
private String firstName;
private String lastName;
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;
}
}
@@ -0,0 +1,28 @@
package com.baeldung.jacksonannotation.serialization.jsonrawvalue;
import com.baeldung.jacksonannotation.domain.Person;
import com.fasterxml.jackson.annotation.JsonRawValue;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
public class Customer extends Person {
@JsonRawValue
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;
}
}
@@ -0,0 +1,32 @@
package com.baeldung.jacksonannotation.serialization.jsonrootname;
import com.baeldung.jacksonannotation.domain.Item;
import com.baeldung.jacksonannotation.domain.Person;
import com.fasterxml.jackson.annotation.JsonRootName;
import java.util.ArrayList;
import java.util.List;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
@JsonRootName("writer")
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;
}
}
@@ -0,0 +1,30 @@
package com.baeldung.jacksonannotation.serialization.jsonserialize;
import com.baeldung.jacksonannotation.domain.Item;
import com.baeldung.jacksonannotation.domain.Person;
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 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;
}
}
@@ -0,0 +1,53 @@
package com.baeldung.jacksonannotation.serialization.jsonserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.math.BigDecimal;
import java.util.Date;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
public class Book extends Item {
private String ISBN;
@JsonSerialize(using = CustomDateSerializer.class)
private Date published;
private BigDecimal pages;
public Book(){
super();
}
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;
}
}
@@ -0,0 +1,36 @@
package com.baeldung.jacksonannotation.serialization.jsonserialize;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
public class CustomDateSerializer extends StdSerializer<Date> {
private static SimpleDateFormat formatter =
new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
public CustomDateSerializer() {
this(null);
}
public CustomDateSerializer(Class<Date> t) {
super(t);
}
@Override
public void serialize(Date value, JsonGenerator gen, SerializerProvider arg2)
throws IOException, JsonProcessingException {
gen.writeString(formatter.format(value));
}
}
@@ -0,0 +1,61 @@
package com.baeldung.jacksonannotation.serialization.jsonserialize;
import com.baeldung.jacksonannotation.domain.Person;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
}
@@ -0,0 +1,40 @@
package com.baeldung.jacksonannotation.serialization.jsonvalue;
import com.baeldung.jacksonannotation.domain.Item;
import com.baeldung.jacksonannotation.domain.Person;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.com
* @version 1.0
*/
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;
}
@JsonValue
public Map<String,String> toJson() {
Map<String,String> values = new HashMap<>();
values.put("name", getFirstName() + " " + getLastName());
return values;
}
}
@@ -0,0 +1,76 @@
package com.baeldung.jacksonannotation.serialization.jsonvalue;
import com.baeldung.jacksonannotation.domain.Author;
import com.baeldung.jacksonannotation.domain.Item;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.List;
/**
* Source code github.com/eugenp/tutorials
*
* @author Alex Theedom www.baeldung.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;
}
@JsonValue
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;
}
}
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>