문제

I'm serializing an array of objects of different types, but all of which are of supertype BasicClass. When I serialize it as such:

@JsonProperty
public BasicClass[] getReferences() {
    return this.refs;
}

it also serializes all the subtype JSON properties. How can I make it only serialize the supertype properties?

도움이 되었습니까?

해결책

You should use the @JsonSerialize annotation. It will allow you to specify a Typing value as either dynamic or static. In your case you want to use the static type rather than waiting til runtime for it to see the specific subclass.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top