Given a simple entity class like this
public class User
{
@JsonProperty
public Calendar createdOn;
@JsonProperty
public String name;
}
Is there a way for me to hook into the jackson streaming API to custom deserialize ONLY the createdOn field? If there's not, then would something like this be possible in the future?
public class User
{
@JsonProperty
@JsonConverter(MyCustomCalendarConverter.class)
public Calendar createdOn;
@JsonProperty
public String name;
}
It appears that I could custom deserialize the entire entity. I'm just curious if there is a way to customize the deserialization just a field at a time in order to, for example, custom parse a particular date format, or read an array of values into a custom entity, etc. while letting Jackson deserialize the rest of the entity normally.
This is how i'm deserializing the date: SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); getObjectMapper(). getDeserializationConfig(). setDateFormat(dateFormat);
This short tutorial shows how the Jackson library can be used to serialize Java object to XML and deserialize them back to objects.
The @JsonDeserialize annotation is used to declare custom deserializer while deserializing JSON to Java object. We can implement a custom deserializer by extending the StdDeserializer class with a generic type Employee and need to override the deserialize() method of StdDeserializer class.
You can define custom serialize a specific field using @JsonSerialize:
@JsonSerialize(using=MuCustomCalendarConverter.class)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With