- 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 注解 - @JsonView
@JsonView 用于控制是否序列化值。
示例 - @JsonView
import java.io.IOException; import java.text.ParseException; import com.fasterxml.jackson.annotation.JsonView; import com.fasterxml.jackson.databind.ObjectMapper; public class JacksonTester { public static void main(String args[]) throws IOException, ParseException { ObjectMapper mapper = new ObjectMapper(); Student student = new Student(1, "Mark", 12); String jsonString = mapper .writerWithDefaultPrettyPrinter() .withView(Views.Public.class) .writeValueAsString(student); System.out.println(jsonString); } } class Student { @JsonView(Views.Public.class) public int id; @JsonView(Views.Public.class) public String name; @JsonView(Views.Internal.class) public int age; Student(int id, String name, int age) { this.id = id; this.name = name; this.age = age; } } class Views { static class Public {} static class Internal extends Public {} }
输出
{ "id" : 1, "name" : "Mark" }
广告