您应该使用
JsonTypeInfo.As.EXTERNAL_PROPERTY而不是
JsonTypeInfo.As.PROPERTY。在这种情况下,您的
Asset课程应如下所示:
class Asset { @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type") @JsonSubTypes({ @JsonSubTypes.Type(value = ImageAssetProperties.class, name = "image"), @JsonSubTypes.Type(value = documentAssetProperties.class, name = "document") }) private AssetProperties properties; public AssetProperties getProperties() { return properties; } public void setProperties(AssetProperties properties) { this.properties = properties; } @Override public String toString() { return "Asset [properties("+properties.getClass().getSimpleName()+")=" + properties + "]"; }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)