我问道:
所以我正在实现一个带有2个子类的抽象类,如下所示:
我按照杰克逊注释中的文档:jackson-annotations和Annotation Type JsonTypeInfo
但我不知道如何://包含Java类名(" com.myempl.ImplClass")作为JSON属性" class"
在抽象类上:
@JsonTypeInfo(use=Id.CLASS, include=As.PROPERTY, property="class")
我收到错误:
在子类中:
@JsonTypeInfo(use=Id.NAME, include=As.WRAPPER_OBJECT)
@JsonSubTypes({com.smartenit.client.business.rest.CapabilityWhenReadingAllDevices.class,
com.smartenit.client.business.rest.CapabilityWhenRequestingAttribute.class})
我收到错误:
答案 0 :(得分:0)
我认为Jackson API已经发展了。 我尝试了使用restlet 2.2(利用jackson 2.2)的示例注释(位于抽象类):
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = As.PROPERTY, property = "@class")
@JsonSubTypes({ @Type(value = Impl1.class, name = "impl1"),
@Type(value = Impl2.class, name = "impl2") })
你可以尝试一下吗?