How to use Jackson JsonSubTypes annotation in Kotlin

I believe this has been resolved and nowadays you can write it like this:

import com.fasterxml.jackson.annotation.JsonSubTypes
import com.fasterxml.jackson.annotation.JsonTypeInfo

@JsonTypeInfo(
   use = JsonTypeInfo.Id.NAME,
   include = 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"))
interface Note

Note the missing @ and class notation in the JsonSubTypes.Type.

Leave a Comment