[BAEL-19673] - Move articles out of jackson part 1
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package com.baeldung.jackson.annotation;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||
|
||||
public class AliasBean {
|
||||
|
||||
@JsonAlias({ "fName", "f_name" })
|
||||
private String firstName;
|
||||
|
||||
private String lastName;
|
||||
|
||||
public AliasBean() {
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.jackson.annotation;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class BeanWithCreator {
|
||||
public int id;
|
||||
public String name;
|
||||
|
||||
@JsonCreator
|
||||
public BeanWithCreator(@JsonProperty("id") final int id, @JsonProperty("theName") final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.baeldung.jackson.annotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.Date;
|
||||
|
||||
import com.baeldung.jackson.annotation.BeanWithCustomAnnotation.CustomAnnotation;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
|
||||
@CustomAnnotation
|
||||
public class BeanWithCustomAnnotation {
|
||||
public int id;
|
||||
public String name;
|
||||
public Date dateCreated;
|
||||
|
||||
public BeanWithCustomAnnotation() {
|
||||
|
||||
}
|
||||
|
||||
public BeanWithCustomAnnotation(final int id, final String name, final Date dateCreated) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.dateCreated = dateCreated;
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@JacksonAnnotationsInside
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
@JsonPropertyOrder({ "name", "id", "dateCreated" })
|
||||
public @interface CustomAnnotation {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.jackson.annotation;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFilter;
|
||||
|
||||
@JsonFilter("myFilter")
|
||||
public class BeanWithFilter {
|
||||
public int id;
|
||||
public String name;
|
||||
|
||||
public BeanWithFilter() {
|
||||
|
||||
}
|
||||
|
||||
public BeanWithFilter(final int id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.baeldung.jackson.annotation;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonGetter;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonSetter;
|
||||
|
||||
public class BeanWithGetter {
|
||||
public int id;
|
||||
private String name;
|
||||
|
||||
public BeanWithGetter() {
|
||||
|
||||
}
|
||||
|
||||
public BeanWithGetter(final int id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@JsonProperty("name")
|
||||
@JsonSetter("name")
|
||||
public void setTheName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@JsonProperty("name")
|
||||
@JsonGetter("name")
|
||||
public String getTheName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.jackson.annotation;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
@JsonIgnoreProperties({ "id" })
|
||||
public class BeanWithIgnore {
|
||||
@JsonIgnore
|
||||
public int id;
|
||||
public String name;
|
||||
|
||||
public BeanWithIgnore() {
|
||||
|
||||
}
|
||||
|
||||
public BeanWithIgnore(final int id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.jackson.annotation;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JacksonInject;
|
||||
|
||||
public class BeanWithInject {
|
||||
@JacksonInject
|
||||
public int id;
|
||||
public String name;
|
||||
|
||||
public BeanWithInject() {
|
||||
|
||||
}
|
||||
|
||||
public BeanWithInject(final int id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.baeldung.jackson.annotation;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAnyGetter;
|
||||
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
|
||||
public class ExtendableBean {
|
||||
public String name;
|
||||
private Map<String, String> properties;
|
||||
|
||||
public ExtendableBean() {
|
||||
properties = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
public ExtendableBean(final String name) {
|
||||
this.name = name;
|
||||
properties = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
@JsonAnySetter
|
||||
public void add(final String key, final String value) {
|
||||
properties.put(key, value);
|
||||
}
|
||||
|
||||
@JsonAnyGetter
|
||||
public Map<String, String> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.baeldung.jackson.annotation;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonGetter;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import com.fasterxml.jackson.annotation.JsonSetter;
|
||||
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
@JsonPropertyOrder({ "name", "id" })
|
||||
public class MyBean {
|
||||
public int id;
|
||||
public String name;
|
||||
|
||||
public MyBean() {
|
||||
|
||||
}
|
||||
|
||||
public MyBean(final int id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@JsonGetter("name")
|
||||
public String getTheName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@JsonSetter("name")
|
||||
public void setTheName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.baeldung.jackson.annotation;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
||||
|
||||
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
|
||||
public class PrivateBean {
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
public PrivateBean() {
|
||||
|
||||
}
|
||||
|
||||
public PrivateBean(final int id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.baeldung.jackson.annotation;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonRawValue;
|
||||
|
||||
public class RawBean {
|
||||
public String name;
|
||||
|
||||
@JsonRawValue
|
||||
public String json;
|
||||
|
||||
public RawBean() {
|
||||
|
||||
}
|
||||
|
||||
public RawBean(final String name, final String json) {
|
||||
this.name = name;
|
||||
this.json = json;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.baeldung.jackson.annotation;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonUnwrapped;
|
||||
|
||||
public class UnwrappedUser {
|
||||
public int id;
|
||||
|
||||
@JsonUnwrapped
|
||||
public Name name;
|
||||
|
||||
public UnwrappedUser() {
|
||||
|
||||
}
|
||||
|
||||
public UnwrappedUser(final int id, final Name name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static class Name {
|
||||
public String firstName;
|
||||
public String lastName;
|
||||
|
||||
public Name() {
|
||||
|
||||
}
|
||||
|
||||
public Name(final String firstName, final String lastName) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.baeldung.jackson.annotation;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreType;
|
||||
|
||||
public class UserWithIgnoreType {
|
||||
public int id;
|
||||
|
||||
public Name name;
|
||||
|
||||
public UserWithIgnoreType() {
|
||||
|
||||
}
|
||||
|
||||
public UserWithIgnoreType(final int id, final Name name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@JsonIgnoreType
|
||||
public static class Name {
|
||||
public String firstName;
|
||||
public String lastName;
|
||||
|
||||
public Name() {
|
||||
|
||||
}
|
||||
|
||||
public Name(final String firstName, final String lastName) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.baeldung.jackson.annotation;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
|
||||
public class Zoo {
|
||||
public Animal animal;
|
||||
|
||||
public Zoo() {
|
||||
|
||||
}
|
||||
|
||||
public Zoo(final Animal animal) {
|
||||
this.animal = animal;
|
||||
}
|
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = As.PROPERTY, property = "type")
|
||||
@JsonSubTypes({ @JsonSubTypes.Type(value = Dog.class, name = "dog"), @JsonSubTypes.Type(value = Cat.class, name = "cat") })
|
||||
public static class Animal {
|
||||
public String name;
|
||||
|
||||
public Animal() {
|
||||
}
|
||||
|
||||
public Animal(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@JsonTypeName("dog")
|
||||
public static class Dog extends Animal {
|
||||
public double barkVolume;
|
||||
|
||||
public Dog() {
|
||||
}
|
||||
|
||||
public Dog(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@JsonTypeName("cat")
|
||||
public static class Cat extends Animal {
|
||||
boolean likesCream;
|
||||
public int lives;
|
||||
|
||||
public Cat() {
|
||||
}
|
||||
|
||||
public Cat(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.baeldung.jackson.annotation.bidirection;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||
|
||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
|
||||
public class ItemWithIdentity {
|
||||
public int id;
|
||||
public String itemName;
|
||||
public UserWithIdentity owner;
|
||||
|
||||
public ItemWithIdentity() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ItemWithIdentity(final int id, final String itemName, final UserWithIdentity owner) {
|
||||
this.id = id;
|
||||
this.itemName = itemName;
|
||||
this.owner = owner;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.jackson.annotation.bidirection;
|
||||
|
||||
public class ItemWithIgnore {
|
||||
public int id;
|
||||
public String itemName;
|
||||
public UserWithIgnore owner;
|
||||
|
||||
public ItemWithIgnore() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ItemWithIgnore(final int id, final String itemName, final UserWithIgnore owner) {
|
||||
this.id = id;
|
||||
this.itemName = itemName;
|
||||
this.owner = owner;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.baeldung.jackson.annotation.bidirection;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
|
||||
public class ItemWithRef {
|
||||
public int id;
|
||||
public String itemName;
|
||||
|
||||
@JsonManagedReference
|
||||
public UserWithRef owner;
|
||||
|
||||
public ItemWithRef() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ItemWithRef(final int id, final String itemName, final UserWithRef owner) {
|
||||
this.id = id;
|
||||
this.itemName = itemName;
|
||||
this.owner = owner;
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.baeldung.jackson.annotation.bidirection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||
|
||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
|
||||
public class UserWithIdentity {
|
||||
public int id;
|
||||
public String name;
|
||||
public List<ItemWithIdentity> userItems;
|
||||
|
||||
public UserWithIdentity() {
|
||||
super();
|
||||
}
|
||||
|
||||
public UserWithIdentity(final int id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
userItems = new ArrayList<ItemWithIdentity>();
|
||||
}
|
||||
|
||||
public void addItem(final ItemWithIdentity item) {
|
||||
userItems.add(item);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.baeldung.jackson.annotation.bidirection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
public class UserWithIgnore {
|
||||
public int id;
|
||||
public String name;
|
||||
|
||||
@JsonIgnore
|
||||
public List<ItemWithIgnore> userItems;
|
||||
|
||||
public UserWithIgnore() {
|
||||
super();
|
||||
}
|
||||
|
||||
public UserWithIgnore(final int id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
userItems = new ArrayList<ItemWithIgnore>();
|
||||
}
|
||||
|
||||
public void addItem(final ItemWithIgnore item) {
|
||||
userItems.add(item);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.baeldung.jackson.annotation.bidirection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
|
||||
public class UserWithRef {
|
||||
public int id;
|
||||
public String name;
|
||||
|
||||
@JsonBackReference
|
||||
public List<ItemWithRef> userItems;
|
||||
|
||||
public UserWithRef() {
|
||||
super();
|
||||
}
|
||||
|
||||
public UserWithRef(final int id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
userItems = new ArrayList<ItemWithRef>();
|
||||
}
|
||||
|
||||
public void addItem(final ItemWithRef item) {
|
||||
userItems.add(item);
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.baeldung.jackson.annotation.date;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
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;
|
||||
|
||||
public class CustomDateDeserializer extends StdDeserializer<Date> {
|
||||
|
||||
private static final long serialVersionUID = -5451717385630622729L;
|
||||
private SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
|
||||
|
||||
public CustomDateDeserializer() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public CustomDateDeserializer(final Class<?> vc) {
|
||||
super(vc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date deserialize(final JsonParser jsonparser, final DeserializationContext context) throws IOException, JsonProcessingException {
|
||||
final String date = jsonparser.getText();
|
||||
try {
|
||||
return formatter.parse(date);
|
||||
} catch (final ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.baeldung.jackson.annotation.date;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
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;
|
||||
|
||||
public class CustomDateSerializer extends StdSerializer<Date> {
|
||||
|
||||
private static final long serialVersionUID = -2894356342227378312L;
|
||||
private SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
|
||||
|
||||
public CustomDateSerializer() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public CustomDateSerializer(final Class<Date> t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(final Date value, final JsonGenerator gen, final SerializerProvider arg2) throws IOException, JsonProcessingException {
|
||||
gen.writeString(formatter.format(value));
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.baeldung.jackson.annotation.date;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
public class EventWithFormat {
|
||||
public String name;
|
||||
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss")
|
||||
public Date eventDate;
|
||||
|
||||
public EventWithFormat() {
|
||||
super();
|
||||
}
|
||||
|
||||
public EventWithFormat(final String name, final Date eventDate) {
|
||||
this.name = name;
|
||||
this.eventDate = eventDate;
|
||||
}
|
||||
|
||||
public Date getEventDate() {
|
||||
return eventDate;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.baeldung.jackson.annotation.date;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
public class EventWithSerializer {
|
||||
public String name;
|
||||
|
||||
@JsonDeserialize(using = CustomDateDeserializer.class)
|
||||
@JsonSerialize(using = CustomDateSerializer.class)
|
||||
public Date eventDate;
|
||||
|
||||
public EventWithSerializer() {
|
||||
super();
|
||||
}
|
||||
|
||||
public EventWithSerializer(final String name, final Date eventDate) {
|
||||
this.name = name;
|
||||
this.eventDate = eventDate;
|
||||
}
|
||||
|
||||
public Date getEventDate() {
|
||||
return eventDate;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package com.baeldung.jackson.annotation.deserialization;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.baeldung.jackson.annotation.dtos.ItemWithSerializer;
|
||||
import com.baeldung.jackson.annotation.dtos.User;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||
import com.fasterxml.jackson.databind.node.IntNode;
|
||||
|
||||
public class ItemDeserializerOnClass extends StdDeserializer<ItemWithSerializer> {
|
||||
|
||||
private static final long serialVersionUID = 5579141241817332594L;
|
||||
|
||||
public ItemDeserializerOnClass() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public ItemDeserializerOnClass(final Class<?> vc) {
|
||||
super(vc);
|
||||
}
|
||||
|
||||
/**
|
||||
* {"id":1,"itemNr":"theItem","owner":2}
|
||||
*/
|
||||
@Override
|
||||
public ItemWithSerializer deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||||
final JsonNode node = jp.getCodec()
|
||||
.readTree(jp);
|
||||
final int id = (Integer) ((IntNode) node.get("id")).numberValue();
|
||||
final String itemName = node.get("itemName")
|
||||
.asText();
|
||||
final int userId = (Integer) ((IntNode) node.get("owner")).numberValue();
|
||||
|
||||
return new ItemWithSerializer(id, itemName, new User(userId, null));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.baeldung.jackson.annotation.dtos;
|
||||
|
||||
public class Item {
|
||||
public int id;
|
||||
public String itemName;
|
||||
public User owner;
|
||||
|
||||
public Item() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Item(final int id, final String itemName, final User owner) {
|
||||
this.id = id;
|
||||
this.itemName = itemName;
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getItemName() {
|
||||
return itemName;
|
||||
}
|
||||
|
||||
public User getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.baeldung.jackson.annotation.dtos;
|
||||
|
||||
import com.baeldung.jackson.annotation.deserialization.ItemDeserializerOnClass;
|
||||
import com.baeldung.jackson.annotation.serialization.ItemSerializerOnClass;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
@JsonSerialize(using = ItemSerializerOnClass.class)
|
||||
@JsonDeserialize(using = ItemDeserializerOnClass.class)
|
||||
public class ItemWithSerializer {
|
||||
public final int id;
|
||||
public final String itemName;
|
||||
public final User owner;
|
||||
|
||||
public ItemWithSerializer(final int id, final String itemName, final User owner) {
|
||||
this.id = id;
|
||||
this.itemName = itemName;
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getItemName() {
|
||||
return itemName;
|
||||
}
|
||||
|
||||
public User getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.baeldung.jackson.annotation.dtos;
|
||||
|
||||
public class User {
|
||||
public int id;
|
||||
public String name;
|
||||
|
||||
public User() {
|
||||
super();
|
||||
}
|
||||
|
||||
public User(final int id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.baeldung.jackson.annotation.dtos.withEnum;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
public enum DistanceEnumWithValue {
|
||||
KILOMETER("km", 1000), MILE("miles", 1609.34), METER("meters", 1), INCH("inches", 0.0254), CENTIMETER("cm", 0.01), MILLIMETER("mm", 0.001);
|
||||
|
||||
private String unit;
|
||||
private final double meters;
|
||||
|
||||
private DistanceEnumWithValue(String unit, double meters) {
|
||||
this.unit = unit;
|
||||
this.meters = meters;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public double getMeters() {
|
||||
return meters;
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
public void setUnit(String unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.jackson.annotation.exception;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonRootName;
|
||||
|
||||
@JsonRootName(value = "user")
|
||||
public class UserWithRoot {
|
||||
public int id;
|
||||
public String name;
|
||||
|
||||
public UserWithRoot() {
|
||||
super();
|
||||
}
|
||||
|
||||
public UserWithRoot(final int id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.jackson.annotation.exception;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonRootName;
|
||||
|
||||
@JsonRootName(value = "user", namespace="users")
|
||||
public class UserWithRootNamespace {
|
||||
public int id;
|
||||
public String name;
|
||||
|
||||
public UserWithRootNamespace() {
|
||||
super();
|
||||
}
|
||||
|
||||
public UserWithRootNamespace(final int id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.baeldung.jackson.annotation.jsonview;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
|
||||
public class Item {
|
||||
@JsonView(Views.Public.class)
|
||||
public int id;
|
||||
|
||||
@JsonView(Views.Public.class)
|
||||
public String itemName;
|
||||
|
||||
@JsonView(Views.Internal.class)
|
||||
public String ownerName;
|
||||
|
||||
public Item() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Item(final int id, final String itemName, final String ownerName) {
|
||||
this.id = id;
|
||||
this.itemName = itemName;
|
||||
this.ownerName = ownerName;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getItemName() {
|
||||
return itemName;
|
||||
}
|
||||
|
||||
public String getOwnerName() {
|
||||
return ownerName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.baeldung.jackson.annotation.jsonview;
|
||||
|
||||
public class Views {
|
||||
public static class Public {
|
||||
}
|
||||
|
||||
public static class Internal extends Public {
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.baeldung.jackson.annotation.serialization;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.baeldung.jackson.annotation.dtos.Item;
|
||||
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;
|
||||
|
||||
public class ItemSerializer extends StdSerializer<Item> {
|
||||
|
||||
private static final long serialVersionUID = 6739170890621978901L;
|
||||
|
||||
public ItemSerializer() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public ItemSerializer(final Class<Item> t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void serialize(final Item value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException {
|
||||
jgen.writeStartObject();
|
||||
jgen.writeNumberField("id", value.id);
|
||||
jgen.writeStringField("itemName", value.itemName);
|
||||
jgen.writeNumberField("owner", value.owner.id);
|
||||
jgen.writeEndObject();
|
||||
}
|
||||
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.baeldung.jackson.annotation.serialization;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.baeldung.jackson.annotation.dtos.ItemWithSerializer;
|
||||
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;
|
||||
|
||||
public class ItemSerializerOnClass extends StdSerializer<ItemWithSerializer> {
|
||||
|
||||
private static final long serialVersionUID = -1760959597313610409L;
|
||||
|
||||
public ItemSerializerOnClass() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public ItemSerializerOnClass(final Class<ItemWithSerializer> t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void serialize(final ItemWithSerializer value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException {
|
||||
jgen.writeStartObject();
|
||||
jgen.writeNumberField("id", value.id);
|
||||
jgen.writeStringField("itemName", value.itemName);
|
||||
jgen.writeNumberField("owner", value.owner.id);
|
||||
jgen.writeEndObject();
|
||||
}
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.baeldung.jackson.bidirection;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
|
||||
public class CustomListDeserializer extends StdDeserializer<List<ItemWithSerializer>> {
|
||||
|
||||
private static final long serialVersionUID = 1095767961632979804L;
|
||||
|
||||
public CustomListDeserializer() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public CustomListDeserializer(final Class<?> vc) {
|
||||
super(vc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemWithSerializer> deserialize(final JsonParser jsonparser, final DeserializationContext context) throws IOException, JsonProcessingException {
|
||||
return new ArrayList<ItemWithSerializer>();
|
||||
}
|
||||
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.baeldung.jackson.bidirection;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
|
||||
public class CustomListSerializer extends StdSerializer<List<ItemWithSerializer>> {
|
||||
|
||||
private static final long serialVersionUID = 3698763098000900856L;
|
||||
|
||||
public CustomListSerializer() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public CustomListSerializer(final Class<List<ItemWithSerializer>> t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(final List<ItemWithSerializer> items, final JsonGenerator generator, final SerializerProvider provider) throws IOException, JsonProcessingException {
|
||||
final List<Integer> ids = new ArrayList<Integer>();
|
||||
for (final ItemWithSerializer item : items) {
|
||||
ids.add(item.id);
|
||||
}
|
||||
generator.writeObject(ids);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.jackson.bidirection;
|
||||
|
||||
public class Item {
|
||||
public int id;
|
||||
public String itemName;
|
||||
public User owner;
|
||||
|
||||
public Item() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Item(final int id, final String itemName, final User owner) {
|
||||
this.id = id;
|
||||
this.itemName = itemName;
|
||||
this.owner = owner;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.baeldung.jackson.bidirection;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||
|
||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
|
||||
public class ItemWithIdentity {
|
||||
public int id;
|
||||
public String itemName;
|
||||
public UserWithIdentity owner;
|
||||
|
||||
public ItemWithIdentity() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ItemWithIdentity(final int id, final String itemName, final UserWithIdentity owner) {
|
||||
this.id = id;
|
||||
this.itemName = itemName;
|
||||
this.owner = owner;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.jackson.bidirection;
|
||||
|
||||
public class ItemWithIgnore {
|
||||
public int id;
|
||||
public String itemName;
|
||||
public UserWithIgnore owner;
|
||||
|
||||
public ItemWithIgnore() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ItemWithIgnore(final int id, final String itemName, final UserWithIgnore owner) {
|
||||
this.id = id;
|
||||
this.itemName = itemName;
|
||||
this.owner = owner;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.baeldung.jackson.bidirection;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
|
||||
public class ItemWithRef {
|
||||
public int id;
|
||||
public String itemName;
|
||||
|
||||
@JsonManagedReference
|
||||
public UserWithRef owner;
|
||||
|
||||
public ItemWithRef() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ItemWithRef(final int id, final String itemName, final UserWithRef owner) {
|
||||
this.id = id;
|
||||
this.itemName = itemName;
|
||||
this.owner = owner;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.jackson.bidirection;
|
||||
|
||||
public class ItemWithSerializer {
|
||||
public int id;
|
||||
public String itemName;
|
||||
public UserWithSerializer owner;
|
||||
|
||||
public ItemWithSerializer() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ItemWithSerializer(final int id, final String itemName, final UserWithSerializer owner) {
|
||||
this.id = id;
|
||||
this.itemName = itemName;
|
||||
this.owner = owner;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.baeldung.jackson.bidirection;
|
||||
|
||||
import com.baeldung.jackson.bidirection.jsonview.Views;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
|
||||
public class ItemWithView {
|
||||
@JsonView(Views.Public.class)
|
||||
public int id;
|
||||
|
||||
@JsonView(Views.Public.class)
|
||||
public String itemName;
|
||||
|
||||
@JsonView(Views.Public.class)
|
||||
public UserWithView owner;
|
||||
|
||||
public ItemWithView() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ItemWithView(final int id, final String itemName, final UserWithView owner) {
|
||||
this.id = id;
|
||||
this.itemName = itemName;
|
||||
this.owner = owner;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.jackson.bidirection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class User {
|
||||
public int id;
|
||||
public String name;
|
||||
public List<Item> userItems;
|
||||
|
||||
public User() {
|
||||
super();
|
||||
}
|
||||
|
||||
public User(final int id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
userItems = new ArrayList<Item>();
|
||||
}
|
||||
|
||||
public void addItem(final Item item) {
|
||||
userItems.add(item);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.baeldung.jackson.bidirection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||
|
||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
|
||||
public class UserWithIdentity {
|
||||
public int id;
|
||||
public String name;
|
||||
public List<ItemWithIdentity> userItems;
|
||||
|
||||
public UserWithIdentity() {
|
||||
super();
|
||||
}
|
||||
|
||||
public UserWithIdentity(final int id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
userItems = new ArrayList<ItemWithIdentity>();
|
||||
}
|
||||
|
||||
public void addItem(final ItemWithIdentity item) {
|
||||
userItems.add(item);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.baeldung.jackson.bidirection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
public class UserWithIgnore {
|
||||
public int id;
|
||||
public String name;
|
||||
|
||||
@JsonIgnore
|
||||
public List<ItemWithIgnore> userItems;
|
||||
|
||||
public UserWithIgnore() {
|
||||
super();
|
||||
}
|
||||
|
||||
public UserWithIgnore(final int id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
userItems = new ArrayList<ItemWithIgnore>();
|
||||
}
|
||||
|
||||
public void addItem(final ItemWithIgnore item) {
|
||||
userItems.add(item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.baeldung.jackson.bidirection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
|
||||
public class UserWithRef {
|
||||
public int id;
|
||||
public String name;
|
||||
|
||||
@JsonBackReference
|
||||
public List<ItemWithRef> userItems;
|
||||
|
||||
public UserWithRef() {
|
||||
super();
|
||||
}
|
||||
|
||||
public UserWithRef(final int id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
userItems = new ArrayList<ItemWithRef>();
|
||||
}
|
||||
|
||||
public void addItem(final ItemWithRef item) {
|
||||
userItems.add(item);
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.baeldung.jackson.bidirection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
public class UserWithSerializer {
|
||||
public int id;
|
||||
public String name;
|
||||
|
||||
@JsonSerialize(using = CustomListSerializer.class)
|
||||
@JsonDeserialize(using = CustomListDeserializer.class)
|
||||
public List<ItemWithSerializer> userItems;
|
||||
|
||||
public UserWithSerializer() {
|
||||
super();
|
||||
}
|
||||
|
||||
public UserWithSerializer(final int id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
userItems = new ArrayList<ItemWithSerializer>();
|
||||
}
|
||||
|
||||
public void addItem(final ItemWithSerializer item) {
|
||||
userItems.add(item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.baeldung.jackson.bidirection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.baeldung.jackson.bidirection.jsonview.Views;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
|
||||
public class UserWithView {
|
||||
@JsonView(Views.Public.class)
|
||||
public int id;
|
||||
|
||||
@JsonView(Views.Public.class)
|
||||
public String name;
|
||||
|
||||
@JsonView(Views.Internal.class)
|
||||
public List<ItemWithView> userItems;
|
||||
|
||||
public UserWithView() {
|
||||
super();
|
||||
}
|
||||
|
||||
public UserWithView(final int id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
userItems = new ArrayList<ItemWithView>();
|
||||
}
|
||||
|
||||
public void addItem(final ItemWithView item) {
|
||||
userItems.add(item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.baeldung.jackson.bidirection.jsonview;
|
||||
|
||||
public class Views {
|
||||
public static class Public {
|
||||
}
|
||||
|
||||
public static class Internal extends Public {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.baeldung.jackson.domain;
|
||||
|
||||
public class Person {
|
||||
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
|
||||
public Person(String firstName, String lastName) {
|
||||
super();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.baeldung.jackson.format;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.baeldung.jackson.domain.Person;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
/**
|
||||
* @author Jay Sridhar
|
||||
* @version 1.0
|
||||
*/
|
||||
public class User extends Person {
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd@HH:mm:ss.SSSZ")
|
||||
private Date createdDate;
|
||||
|
||||
public User(String firstName, String lastName) {
|
||||
super(firstName, lastName);
|
||||
this.createdDate = new Date();
|
||||
}
|
||||
|
||||
public Date getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd@HH:mm:ss.SSSZ", locale = "en_GB")
|
||||
public Date getCurrentDate() {
|
||||
return new Date();
|
||||
}
|
||||
|
||||
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
|
||||
public Date getDateNum() {
|
||||
return new Date();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user