Problem
- attribute name pId
- Lombok @Data -> getPId()/setPId()
- Java Specification -> second letter should not be capital
- Jackson will follow JSP, handle the set method(setPId)
- first letter P will be lower(p)
- second letter I will be lower (i)
- third letter d will keep lower (d)
- mean will match "pid" to setPId();
Code
@Data
public class DemoObj {
private String pId;
}
public class Client {
public static void main(String[] args) {
// will change to pid
DemoObj demoObj = new DemoObj();
demoObj.setPId("1");
String a = JsonHelper.toJson(demoObj);
System.out.println(a);
// will match setPId method
String b = "{\"pid\":\"1\"}";
DemoObj demoObj1 = JsonHelper.readValue(b, DemoObj.class);
System.out.println(demoObj1.getPId());
// will not match
String c = "{\"pId\":\"1\"}";
DemoObj demoObj2 = JsonHelper.readValue(c, DemoObj.class);
System.out.println(demoObj2.getPId());
}
}
{"pid":"1"}
1
null
Comment
- need to restrict do not use "aB%" format as attribute
本文由 Ivan Dong 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Jun 13, 2023 at 09:58 am