fastjson中@jsonType注解的使用
2017-06-20 15:07
543 查看
1.@JSONType的使用
@JSONType(includes = {"name","sex"})
@JSONType(ignores ={"id", "sex"})
放在实体类中就会只装配列举的字段,
2.@JSONField的使用
放在实体类中的某个字段上面
protected class H5PayConfig {
}
上面两个注解主要区别就是一个是在实体类上面,还有一个是添加在实体类中的某些字段上或者是方法上,均不需要实现序列化的接口
下面是粘贴
1、在实体类上的字段使用@JSONField定制序列化:
//配置序列化的时候,不序列化id
@JSONField(serialize=false)
private int id;
private String name;// 姓名
private int age; //年龄
// 配置序列化的名称
@JSONField(name="gender")
public String sex;
2、在类上通过@JSONType定制序列化:
//配置序列化的时候,不序列化id sex
@JSONType(ignores ={"id", "sex"})
public class Uoimplements Serializable {}
// 配置序列化的时候,序列化name 和sex
@JSONType(includes={"name","sex"})
public class Uo1implements Serializable {}
注:注意和@JSONField不同的是,@JSONType是配置在类上的,而@JSONField是配置在字段和方法上的。
@JSONType(includes = {"name","sex"})
@JSONType(ignores ={"id", "sex"})
放在实体类中就会只装配列举的字段,
2.@JSONField的使用
放在实体类中的某个字段上面
protected class H5PayConfig {
@JSONField(name = "appId") private String appId;
}
上面两个注解主要区别就是一个是在实体类上面,还有一个是添加在实体类中的某些字段上或者是方法上,均不需要实现序列化的接口
下面是粘贴
1、在实体类上的字段使用@JSONField定制序列化:
//配置序列化的时候,不序列化id
@JSONField(serialize=false)
private int id;
private String name;// 姓名
private int age; //年龄
// 配置序列化的名称
@JSONField(name="gender")
public String sex;
2、在类上通过@JSONType定制序列化:
//配置序列化的时候,不序列化id sex
@JSONType(ignores ={"id", "sex"})
public class Uoimplements Serializable {}
// 配置序列化的时候,序列化name 和sex
@JSONType(includes={"name","sex"})
public class Uo1implements Serializable {}
注:注意和@JSONField不同的是,@JSONType是配置在类上的,而@JSONField是配置在字段和方法上的。
相关文章推荐
- fastjson使用@JSONField、@JSONType、SerializeFilter定制序列化
- springmvc与fastjson的整合,注解@RequestBody的使用
- FastJson中@JSONField注解使用
- FastJson中@JSONField注解使用
- springmvc与fastjson的整合,注解@RequestBody的使用
- FastJson中@JSONField注解使用
- FastJson中@JSONField注解使用
- springmvc与fastjson的整合,注解@RequestBody的使用
- 使用Fastjson序列化与反序列化对象
- struts2 json注解 时 报错:The Result type [json] which is defined in the Result annotation on the clas
- 使用fastjson key和属性名不一致问题
- fastjson 的使用
- Json解析工具Jackson(使用注解) .
- 使用fastjson导致主键自增列错误 Failed to insert row into content:
- FastJson使用
- JAVA-使用FastJson解析复杂JSON数据
- 使用fastJson 来解析 json
- fastjson的简单使用
- fastjson使用方法实例
- 阿里巴巴 - FastJson使用简介