- 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 注解 - @JsonFilter
@JsonFilter 用于在序列化/反序列化期间应用筛选条件,例如使用或不使用哪些属性。
示例 - @JsonFilter
import java.io.IOException; import java.text.ParseException; import com.fasterxml.jackson.annotation.JsonFilter; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ser.FilterProvider; import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; public class JacksonTester { public static void main(String args[]) throws IOException, ParseException { ObjectMapper mapper = new ObjectMapper(); Student student = new Student(1,13, "Mark"); FilterProvider filters = new SimpleFilterProvider() .addFilter( "nameFilter", SimpleBeanPropertyFilter.filterOutAllExcept("name")); String jsonString = mapper.writer(filters) .withDefaultPrettyPrinter() .writeValueAsString(student); System.out.println(jsonString); } } @JsonFilter("nameFilter") class Student { public int id; public int rollNo; public String name; Student(int id, int rollNo, String name) { this.id = id; this.rollNo = rollNo; this.name = name; } }
输出
{ "name" : "Mark" }
广告