David
David

Reputation: 361

parse .yml as an object (Kotlin)

I have a .yml

anchor: &my_anchor
  id: my_id
  name: my_name

ref: *my_anchor

Here are my classes in the code

class Response {
    latenit var anchor: MyAnchor
    lateinit var ref: MyAnchor
}

open class MyAnchor {

    lateinit var id: String
    lateinit var name: String
}

and here is a SnakeYaml code to parse a file

val result = Yaml(Constructor(Response::class.java)).loadAs(content, Response::class.java)

Everything seems to be ok except the fact that the property "ref" of the class "Response" has type "LinkedHashMap" but not "MyAnchor". I got a message like this

field ref has type MyAnchor, got java.util.LinkedHashMap

Maybe I should set some tags? I Will be grateful if you help me.

Upvotes: 0

Views: 4268

Answers (1)

David
David

Reputation: 361

I found the solution. The problem is that the class MyAnchor::class is an open one. Any model entity class should be final

Upvotes: 1

Related Questions