9
当bean中的属性大小写和json数据中不一致时,反序列化后序列化导致属性数据丢失,测试代码如下
public static void main(String[] args) {
String s = "{\"USER_NAME\": \"faster\"}";
User user = JSON.parseObject(s, User.class);
System.out.println("===>" + user.getUsername());
System.out.println("===>" + user.getUser_name());
System.out.println(JSON.toJSONString(user));
}
public static class User {
private String user_name;
private String username;
public String getUser_name() {
return user_name;
}
public void setUser_name(String user_name) {
this.user_name = user_name;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
测试结果为如下
===>faster
===>null
{"username":"faster"}
这种情况应该如何解决