Code: Select all
@Schema(
discriminatorMapping = {
@DiscriminatorMapping(value = "type1", schema = Type1.class),
@DiscriminatorMapping(value = "type2", schema = Type2.class),
@DiscriminatorMapping(value = "type3", schema = Type3.class),
},
discriminatorProperty = "type",
oneOf = {Type1.class,
Type2.class,
Type3.class
}
)
public interface MainInterface {
@Schema(
requiredMode = Schema.RequiredMode.REQUIRED,
example = "type1"
)
Type getType();
}
< /code>
Es gibt Eigenschaften, die über untergeordnete Schnittstellen geteilt werden. Daher möchten wir die gemeinsam genutzten Geters im MainInterface
Code: Select all
public interface SharedProperties {
String getName();
String getDescription();
}
Code: Select all
@JsonIgnoreProperties(
value = {"type"},
allowSetters = true
)
@JsonTypeInfo(
use = Id.NAME,
include = As.PROPERTY,
property = "type",
visible = true
)
@JsonSubTypes({@Type(
value = Type1.class,
name = "type1"
), @Type(
value = Type2.class,
name = "type2"
), @Type(
value = Type3.class,
name = "type3"
)})
public interface MainInterface {
Type getType();
}
< P> Wir haben auch versucht, die Methoden direkt zu MainInterface hinzuzufügen, aber der Generator ignoriert sie.