Jackson Annotations Tutorial
Selected Reading
- Jackson - Discussion
- Jackson - Useful Resources
- Jackson - Quick Guide
- Disable Annotation
- MixIn Annotations
- Custom Annotation
- Jackson - @JsonFilter
- Jackson - @JsonIdentityInfo
- @JsonBackReference
- @JsonManagedReference
- Jackson - @JsonView
- Jackson - @JsonUnwrapped
- Jackson - @JsonFormat
- Jackson - @JsonProperty
- Jackson - @JsonTypeName
- Jackson - @JsonSubTypes
- Jackson - @JsonTypeInfo
- Jackson - @JsonAutoDetect
- Jackson - @JsonInclude
- Jackson - @JsonIgnoreType
- Jackson - @JsonIgnore
- @JsonIgnoreProperties
- @JsonEnumDefaultValue
- Jackson - @JsonDeserialize
- Jackson - @JsonSetter
- Jackson - @JsonAnySetter
- Jackson - @JacksonInject
- Jackson - @JsonCreator
- Jackson - @JsonSerialize
- Jackson - @JsonRootName
- Jackson - @JsonValue
- Jackson - @JsonRawValue
- @JsonPropertyOrder
- Jackson - @JsonGetter
- Jackson - @JsonAnyGetter
- Jackson - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Jackson - @JsonFormat
Jackson Annotations - @JsonFormat
@JsonFormat is used to specify format while seriapzation or de-seriapzation. It is mostly used with Date fields.
Example - @JsonFormat
import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.ObjectMapper; pubpc class JacksonTester { pubpc static void main(String args[]) throws IOException, ParseException { ObjectMapper mapper = new ObjectMapper(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy"); Date date = simpleDateFormat.parse("20-12-1984"); Student student = new Student(1, date); String jsonString = mapper .writerWithDefaultPrettyPrinter() .writeValueAsString(student); System.out.println(jsonString); } } class Student { pubpc int id; @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy") pubpc Date birthDate; Student(int id, Date birthDate){ this.id = id; this.birthDate = birthDate; } }
Output
{ "id" : 1, "birthDate" : "19-12-1984" }Advertisements