用fastjson 序列化实体类时 当属性为私有时 会出现错误
public class CancelReason { private String cancelReason; public CancelReason(String cancelReason) { this.cancelReason = cancelReason; } public String getcancelReason() { return cancelReason; } public void setcancelReason(String cancelReason) { this.cancelReason = cancelReason; } }JSON.toJSONString(new CancelReason("xxx"))得出的结果是{}
public class CancelReason { public String cancelReason; public CancelReason(String cancelReason) { this.cancelReason = cancelReason; } public String getcancelReason() { return cancelReason; } public void setcancelReason(String cancelReason) { this.cancelReason = cancelReason; } }JSON.toJSONString(new CancelReason("xxx"))得出的结果是{"cancelReason":"xxx"}
而用gson 不论上述那种情况都能正确解析 o(︶︿︶)o 唉