سؤال

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