tools icon indicating copy to clipboard operation
tools copied to clipboard

Add support for annotating methods with @JsonProperty

Open wowselim opened this issue 3 years ago • 0 comments

Right now it's not possible to annotate a function with @JsonProperty and have it be included in the json.

For example, following kotlin code will be serialized into an empty json object:

class Obj {
    val name
        get() = "John Doe"
}

If @JsonProperty would be allowed for methods, we could write the above code as follows:

class Obj {
    @get:JsonProperty("name")
    val name
        get() = "John Doe"
}

And have it be included in the serialized form. Alternatively, the serialization could include all getters by default. Jackson's ObjectMapper does the same:

class Obj {
    val name
        get() = "John Doe"
}
println(ObjectMapper().writeValueAsString(Obj()))

prints

{"name":"John Doe"}

wowselim avatar Aug 02 '22 06:08 wowselim