- Jackson 注解教程
- Jackson - 首页
- 序列化注解
- Jackson - @JsonAnyGetter
- Jackson - @JsonGetter
- @JsonPropertyOrder
- Jackson - @JsonRawValue
- Jackson - @JsonValue
- Jackson - @JsonRootName
- Jackson - @JsonSerialize
- 反序列化注解
- Jackson - @JsonCreator
- Jackson - @JacksonInject
- Jackson - @JsonAnySetter
- Jackson - @JsonSetter
- Jackson - @JsonDeserialize
- @JsonEnumDefaultValue
- 属性包含注解
- @JsonIgnoreProperties
- Jackson - @JsonIgnore
- Jackson - @JsonIgnoreType
- Jackson - @JsonInclude
- Jackson - @JsonAutoDetect
- 类型处理注解
- Jackson - @JsonTypeInfo
- Jackson - @JsonSubTypes
- Jackson - @JsonTypeName
- 常规注解
- Jackson - @JsonProperty
- Jackson - @JsonFormat
- Jackson - @JsonUnwrapped
- Jackson - @JsonView
- @JsonManagedReference
- @JsonBackReference
- Jackson - @JsonIdentityInfo
- Jackson - @JsonFilter
- 其他内容
- 自定义注解
- MixIn 注解
- 禁用注解
- Jackson 注解资源
- Jackson - 快速指南
- Jackson - 有用资源
- Jackson - 讨论
Jackson 注解 - @JsonUnwrapped
@JsonUnwrapped 用于反序列化或反序列化过程中取消包装对象的值。
示例 - @JsonUnwrapped
import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import com.fasterxml.jackson.annotation.JsonUnwrapped; import com.fasterxml.jackson.databind.ObjectMapper; public class JacksonTester { public 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.Name name = new Student.Name(); name.first = "Jane"; name.last = "Doe"; Student student = new Student(1, name); String jsonString = mapper .writerWithDefaultPrettyPrinter() .writeValueAsString(student); System.out.println(jsonString); } } class Student { public int id; @JsonUnwrapped public Name name; Student(int id, Name name){ this.id = id; this.name = name; } static class Name { public String first; public String last; } }
输出
{ "id" : 1, "first" : "Jane", "last" : "Doe" }
广告