fastjsonjava字段排序_fastjsontoJSONString()属性排序最近使⽤fastjson序列化对象时,发现输出的json字符串中是按属性进⾏了排序。
public class Person {
private String name;
private Integer age;
private String gender;
private Double height;
private Double weight;
//省略get,set⽅法
}
public class FastJsonTest {
public static void main(String[] args) {
Person person = new Person();
person.setName("Tom");
person.setAge(20);
person.setGender("Male");
person.setHeight(180.5);
person.setWeight(80.5);
System.out.JSONString(person));
}
}
输出:
{"age":20,"gender":"Male","height":180.5,"name":"Tom","weight":80.5}
通过@JSONType,@JSONField注解可以定义属性的顺序
fastjson忽略属性@JSONType(orders={"name","age","gender","height","
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论