jackson-core icon indicating copy to clipboard operation
jackson-core copied to clipboard

JsonIgnoreProperties allowSetters is not working

Open anywnyu opened this issue 9 years ago • 3 comments

@JsonIgnoreProperties(value = { "password" }, ignoreUnknown = true, allowSetters = true) the password cannot deserialize.

当JsonIgnoreProperties注解中allowSetters设为true时,仍然无法反序列化指定的字段.

anywnyu avatar Apr 07 '17 02:04 anywnyu

Thank you for reporting this. Couple of things:

  1. This needs to go in jackson-databind: this package only covers streaming reader/writer (JsonParser/JsonGenerator)
  2. I would need to see code reproduce the problem: class definition(s), code to read json, sample json
  3. Which version is this tested with?

cowtowncoder avatar Apr 07 '17 02:04 cowtowncoder


@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

anywnyu avatar Apr 07 '17 09:04 anywnyu

I think this is issue 1595, fixed for databind in upcoming 2.8.9.

cowtowncoder avatar May 20 '17 22:05 cowtowncoder