1.fastjson序列化不依赖于字段,依赖于方法
package com.alibaba.fastjson;
import com.alibaba.fastjson.JSON;
import java.util.Date;
public class Student {
/**
* 姓名
*/
private String name;
/**
* 学号
*/
private String number;
/**
* 年龄
*/
private Short age;
/**
* 班级
*/
private Integer classNO;
/**
* 入学时间
*/
private Date enterDate;
public String getName() {
return name;
}
public String getNumber() {
return number;
}
public Short getAge() {
return age;
}
public Integer getClassNO() {
return classNO;
}
public Date getEnterDate() {
return enterDate;
}
public String getTeacherName() {
return "张三";
}
public static void main(String[] args) {
/**
* FASTJSON序列化是根据方法来的,不是根据元素来的
*/
Student student = new Student();
student.age = 10;
student.name= "晓明";
student.classNO = 10;
student.enterDate = new Date();
student.number = "00315";
System.out.println(JSON.toJSONString(student));
}
}
三种情况
网友评论