-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected serialization of "internal" properties #71
Comments
Similarly, if you want ignore such properties, you must include the "$backend" suffix in the property name:
|
The Kotlin module is not involved in property selection, and the Java code doesn't know about internal properties. @cowtowncoder is there a way for a module to imply JsonIgnore for some properties? |
@apatrida Nothing specific comes to mind, although perhaps overriding methods in |
Ok, I can take a look at it, but likely i would want this to be a feature switch, because I'm not sure if internal should always mean 'exclude' .... does package local in Java get excluded @cowtowncoder ? |
@apatrida Package local inclusion depends on both per-accessor minimum levels (only So while non-public fields are not auto-discovered, by default, they may be included if there is matching public accessors, for purpose of setting value. |
(Note for other people that struggle to find this on google :)) |
To define the serialized name for the internal property to something else you can use |
For more information: https://kotlinlang.org/docs/reference/annotations.html#annotation-use-site-targets |
@jrgonzalezg also ran into this. Your suggestion nearly works except I had to use |
I wrote previous comment without being in front of a computer, so didn't check the details. There is no single solution cause it depends on actual usage and on the class and the targets generated. For immutable data classes for instance I am using now both But for other custom classes you may need to specify something else like a |
The workaround from @jrgonzalezg is the only option currently. |
Now that I wrote that, it would be possible to un-mangle names like this if needed. Maybe, I would have to think about it and the patterns. It would be fragile because we would be coding to internal naming conventions that could change with ABI versions in the future. |
For example, now the generated naming is:
|
… is affecting how Jackson sees the property names, and is ugly when serializing as JSON
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) |
@Spikhalskiy here's an older issue that I had forgotten about that'd be good to tackle. Not sure if improvements into name-mangling configurability would help Kotlin module automatically remove this odd suffix. |
Memo : internal class A {
internal var number: Int? = null
} // decompiled
public final class A {
@Nullable
private Integer number;
@Nullable
public final Integer getNumber$jackson_module_kotlin() {
return this.number;
}
public final void setNumber$jackson_module_kotlin(@Nullable Integer var1) {
this.number = var1;
}
} It could be fixed by modifying Personally, I would solve this problem by implementing #630. |
The issue of property names in the serialization result differing from the definition in Kotlin will be addressed in #630. |
A property with "internal" visibility is serialized with the unexpected "$backend" suffix, i.e.:
is serialized as:
The text was updated successfully, but these errors were encountered: