简体   繁体   中英

Custom Deserialization of JSON FIELD with Jackson in java?

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.

您可以使用@JsonSerialize定义自定义序列化特定字段:

@JsonSerialize(using=MuCustomCalendarConverter.class)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM