Skip to content

JsonIgnoreProperties.allowSetters is not working in Jackson 2.8 #1595

@anywnyu

Description

@anywnyu
@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions