jackson-module-kotlin: Unexpected serialization of "internal" properties
A property with “internal” visibility is serialized with the unexpected “$backend” suffix, i.e.:
open class Identifiable {
internal var identity: Long? = null
}
is serialized as:
{"identity$backend": null}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 17 (10 by maintainers)
I recently run into this problem and it turned out that someone has removed some lines of code that I didn’t even remember why I have written, but apparently this helps with some problems we had with Koltlin and Jackson and indeed it “fixes” this issue too.
This is objectMapper configuration we use that “fixes” this issue (that is, no more annoying suffixes for your data classes):
(obv, it has bigger effect than that and it may break some other stuff since it affects how properties are handled)
@jrgonzalezg also ran into this. Your suggestion nearly works except I had to use
@get:JsonIgnore
to make it stop serializing my internal property. I’m guessing jackson looks explicitly at the getters rather than the field itself.To define the serialized name for the internal property to something else you can use
@field:JsonProperty("name")
so the annotation is applied to the field overriding thename$module
default. Also@field:JsonIgnore
probably works for ignoring it.