Hello y'all. I'm trying to implement inheritance i...
# jackson-kotlin
e
Hello y'all. I'm trying to implement inheritance in jackson and just wondering if this is the best approach. Any suggestions are appreciated.
Copy code
open class Animal(@JsonProperty("id") val id: Long,
                  @JsonProperty("name")val name: String)

class Dog (id: Long,
           name: String,
           @JsonProperty("favorite_toy")val favoriteToy: String) : Animal(id, name)

fun main () {
    val json = configuredObjectMapper()
            .writeValueAsString(Dog(1, "FIDO", "something"))
    println(json)

    val a =
            configuredObjectMapper().readValue(json, Dog::class.java)
    println("${a.id} ${a.name} ${a.favoriteToy}")


}
j
.readValue<Dog>(json)
is a little nicer
e
thx, what do you think about the implementation? Is there a nicer way to do this?