且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Swagger JaxRS可以使用鉴别符进行ApiModel继承吗?

更新时间:2022-12-04 22:06:24

您的示例对我有很大帮助,所以我认为我应该为您提供帮助,因为我现在就可以使用它!

Your examples helped me alot, so I thought I should help you in return because I got it working now!

您需要告诉序列化/反序列化如何绑定实现:

You need to tell the serialisation/deserialisation how to bind the implementation:

@JsonTypeInfo(
    use = JsonTypeInfo.Id.NAME, // Were binding by providing a name
    include = JsonTypeInfo.As.PROPERTY, // The name is provided in a property
    property = "type", // Property name is type
    visible = true // Retain the value of type after deserialisation
)
@JsonSubTypes({//Below, we define the names and the binding classes.
    @JsonSubTypes.Type(value = Lion.class, name = "Lion"),
    @JsonSubTypes.Type(value = Dog.class, name = "Dog")
})
@ApiModel(value = "Animal", subTypes = {Dog.class, Lion.class}, discriminator = "type")
public class Animal {