How to use Jackson JsonSubTypes annotation in Kotlin -
I'm trying to change some Java code which uses Jackson's @Jespenspace annotation to manage polymorphism. is.
Here is the Java code working:
@JsonTypeInfo (experiment = JsonTypeInfo.Id.NAME included = JsonTypeInfo.As.PROPERTY, property = "type") @ JsonSubTypes ({@ JsonSubTypes.Type (value = Comment.class, name = "CommentNote"), @ JsonSubTypes.Type (value = Photo.class, name = "PhotoNote"), @ JsonSubTypes.Type (value = Document.class, Name = "DocumentNote")}) Public abstract class notes enforceable identification [{...]
Codein code here I think would be equivalent:
JsonTypeInfo (use = JsonTypeInfo, JsonSubTypes.Type (value = javaClass & lt; photo & gt .Id.name, = JsonTypeInfo.As.PROPERTY, property = " ); JsonSubTypes (; Comment & gt;), name = "CommentNote", JsonSubTypes.Type (value = javaClass & lt); (), name = "photo note"), jasonsubtips.tap e (value = javaClass & Intuitive class notes: [...]
But I get the following errors on each three "lt; document & gt; (), name =" DocumentNote " JsonSubTypes.Type "lines:
Kotlin: Continuous Kotlin An annotation parameter should be a compilation time: the annotation class can not be instantiated
any V Doors?
Converts it to the compiler, thanks for reporting it. To resolve this problem, you can import JsonSubTypes.Type
and use it without qualification:
import org.codehaus.jackson.annotate.JsonSubTypes. Type JsonTypeInfo (experiment, type (value = javaClass & lt; photo & gt; (= JsonTypeInfo.Id.NAME, = JsonTypeInfo.As.PROPERTY, property = "type") JsonSubTypes (; Comment & gt (), name = " CommentNote "type (value = javaClass & lt), name =" photo note "), type (value = javaClass & lt; document & gt; (), name =" documentNote ") abstract class note: identifiable {[...]
Comments
Post a Comment