jackson-core
jackson-core copied to clipboard
JsonIgnoreProperties allowSetters is not working
@JsonIgnoreProperties(value = { "password" }, ignoreUnknown = true, allowSetters = true) the password cannot deserialize.
当JsonIgnoreProperties注解中allowSetters设为true时,仍然无法反序列化指定的字段.
Thank you for reporting this. Couple of things:
- This needs to go in
jackson-databind: this package only covers streaming reader/writer (JsonParser/JsonGenerator) - I would need to see code reproduce the problem: class definition(s), code to read json, sample json
- Which version is this tested with?
@JsonIgnoreProperties(value = { "password" }, ignoreUnknown = true, allowSetters = true)
public class JsonTest {
private String username;
private String password;
public JsonTest() {
super();
// TODO Auto-generated constructor stub
}
public JsonTest(String username, String password) {
super();
this.username = username;
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public static void main(String[] args) {
ObjectMapper mapper = new ObjectMapper();
JsonTest json = new JsonTest("user", "password");
try {
System.out.println(mapper.writeValueAsString(json));
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String jsonString = "{ \"username\":\"username\",\"password\":\"password\" }";
try {
json = mapper.readValue(jsonString, JsonTest.class);
System.out.println(json.getPassword());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
the version is 2.8.7. the password cannot deserialize. the output is: {"username":"user"} null
I think this is issue 1595, fixed for databind in upcoming 2.8.9.