I am trying to ignore a property while deserialization, but not serialization.
I have a property(specType
) which is not required for the client to send but while retrieval client should be able to see that property. Means, while GET they should be able to see but while POST they should not see specType.
I tried following combinations but non of them worked. I am using jackson-annotaion 2.9.0
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;
public class A1 {
@JsonProperty(access = Access.READ_ONLY)
private String specType;
public String getSpecType() {
return specType;
}
@JsonIgnore
public void setSpecType(String specType) {
this.specType = specType;
}
}
==
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
public class A1 {
@JsonIgnore
private String specType;
@JsonProperty("specType")
public String getSpecType() {
return specType;
}
@JsonIgnore
public void setSpecType(String specType) {
this.specType = specType;
}
}
==
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties(value = { "specType" }, allowGetters = true)
public class A1 {
private String specType;
public String getSpecType() {
return specType;
}
public void setSpecType(String specType) {
this.specType = specType;
}
}
I am using swagger following swagger versions:
springfox-swagger-ui version 2.9.2
springfox-swagger2 version 2.9.2
Am I missing anything?