Closed
Description
Describe the bug
JsonIgnore is not work when with JsonProperty or JsonFormat。
code:
@JsonIgnore
@JsonProperty("create_time")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
Date createTime;
Version information
2.13.1
To Reproduce
test case:
@Test
void testJsonIgnore() throws JsonProcessingException {
TestIgnorebean tb = new TestIgnorebean();
tb.setCreateTime(new Date());
tb.setAge(10);
tb.setNickName("lizongbo");
ObjectMapper mapper = new ObjectMapper();
JsonInclude.Value full = JsonInclude.Value.construct(Include.ALWAYS, Include.ALWAYS);
mapper.setDefaultPropertyInclusion(full);
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
mapper.enable(Feature.WRITE_BIGDECIMAL_AS_PLAIN);
mapper.setTimeZone(TimeZone.getDefault());
System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(tb));
System.out.println("jackson vesion " + JsonIgnore.class.getPackage().getImplementationVersion());
}
static class TestIgnorebean {
@JsonIgnore
@JsonProperty("nick_name")
String nickName;
@JsonIgnore
@JsonProperty("create_time")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
Date createTime;
int age;
public String getNickName() {
return nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
result:
{
"nickName" : "lizongbo",
"createTime" : 1640089093927,
"age" : 10
}
jackson vesion 2.13.1
// JsonIgnore, JsonFormat and JsonProperty all not work correct.
Expected behavior
need:
{
"age" : 10
}
jackson vesion 2.13.1