为什么objectMapper
它看不到对象的字段设置器Pojo
?
班级User
public class User {
private String ID;
private boolean ACTIVE;
private String UF_PHONE_INNER;
public String getID() {
return ID;
}
public void setID(String ID) {
this.ID = ID;
}
... и т.д.
班级Users
public class Users {
private User[] result;
public User[] getUsers() {
return result;
}
public void setResult(User[] result) {
this.result = result;
}
и т.д....
拆解JSON
log.debug("jsonString is {}",jsonString);
users.setResult(objectMapper.readValue(jsonString, Users.class).getUsers());
我得到:
DEBUG log:71 - jsonString is {"result":[{"ID":"1","ACTIVE":true,...
WARN log:81 - com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "ID" (class ru.bityard.bitrix24.User), not marked as ignorable (3 known properties: "id", "active", "uf_PHONE_INNER"])
我不明白为什么他看到id
而不是ID
???我的印象是解析器将字段ID
视为对象......
杰克逊看到方法
setID
认为该字段将被调用iD
。@JsonProperty
以 java 风格添加注解和名称字段