質問

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