1、关于序列化内部类时:内部类一定是static内部类,且字段为public,否则不能序列化数据到内部类字段上。
正确方式:
public class PersonVO { public Customer xxx; public static class Customer{ public Long customerId; public String customerName; public Date date; public Long getCustomerId() { return customerId; } public void setCustomerId(Long customerId) { this.customerId = customerId; } public String getCustomerName() { return customerName; } public void setCustomerName(String customerName) { this.customerName = customerName; } public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } @Override public String toString() { } } @Override public String toString() { } }
2、字段的格式不要定义为"pGGG"这样的格式:
原因:这样get方法默认生成的是getpGGG(),fastjson,就不能序列化这样的字段了。
解决方法:
1、spring框架自带的Jackson可以序列化这样的字段
2、将pGGG字段改为ppGGG字段,这样默认生成的get方法是getPpGGG()这样的形式,就能序列化了。(备注:字段定义时,如果字母超过两个,头两个字母,一定要小写,不能只有一个小写字母)