1 回答
TA贡献1796条经验 获得超7个赞
尝试这个
@JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = As.PROPERTY, property = "type" )
@JsonSubTypes( { @Type( value = FirstClass.class, name = "first" )
,@Type( value = SecondClass.class, name = "second" )
,@Type( value = ThirdClass.class, name = "third" ) } )
public class Master {
public String name;
}
if ( master instanceof FirstClass){
...
} else if ( master instanceof SecondClass) {
...
} else if ( master instanceof ThirdClass){
...
} else if ( master instanceof Master ){
...
}
并使用此请求来调用主条件
{
"name":"test",
"type":"Master"
}
编辑:您可以使用 @JsonTypeName 作为特定名称
@JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = As.PROPERTY, property = "type" )
@JsonSubTypes( { @Type( value = FirstClass.class, name = "first" )
,@Type( value = SecondClass.class, name = "second" )
,@Type( value = ThirdClass.class, name = "third" ) } )
@JsonTypeName("forth")
public class Master {
public String name;
}
要求
{
"name":"test",
"type":"forth"
}
添加回答
举报