问题
My class looks like this
class Foo {
int x;
public void setX(int x){
this.x=x;
}
public int getX(){
return x;
}
public int getDoubleX(){
return x*2;
}
}
When serializing the class to JSON using Jackson I get an error:
**JSON parse error: Unrecognized field "doubleX"**
I tried annotating with @JsonGetter
but that did not work.
The only thing that seems to work with Jackson is to create a setter that does nothing and annotate it with @JsonIgnore
.
回答1:
Use @JsonIgnoreProperties
annotation:
@JsonIgnoreProperties(ignoreUnknown = true)
class Foo
It should allow to serialise all getters
and skip unknown during deserialisation.
来源:https://stackoverflow.com/questions/55164244/jackson-derived-property-with-getter-only-gives-com-fasterxml-jackson-databind-e