-
Notifications
You must be signed in to change notification settings - Fork 173
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
@JsonProperty
not honored in superclass fields
#474
Comments
That’s pretty interesting. Seems likely a recent issue or we would have seen this previously. |
wild guess: changes in kotlin reflection behavior in 1.5? edit: or maybe it's in jackson-databind and also affects Java? 🤷 |
Happens in j-m-k 2.12 which is based on Kotlin 1.4.21 🤔 |
Hmm, also happens in 2.11 (Kotlin 1.3.72) |
Not a databind issue, this works in Databind on 2.12: import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class JacksonModuleKotlinGithub474 {
static class Parent {
@JsonProperty("parent-prop")
String parent;
public Parent(String parent) {
this.parent = parent;
}
}
static class Child extends Parent {
@JsonProperty("child-prop")
String child;
public Child(String child) {
super(child);
this.child = child;
}
}
@Test
public void jsonPropertyAnnotationRespectedOnParentClass() throws Exception {
assertEquals(
"{\"parent-prop\":\"foo\",\"child-prop\":\"foo\"}",
(new ObjectMapper()).writeValueAsString(new Child("foo"))
);
}
} |
Any update around this issue? Currently seeing it with 2.13.3 and Kotlin 1.6. I've tried a number of older versions, but I've seen the problem with each. The earliest I tried was 2.10.x. What works is to annotate the getter method, but that does not seem like the proper approach. @get:JsonProperty("myPropName") |
It is closed as a duplicate of #658. |
Describe the bug
Controlling the serialized field name with
@JsonProperty
doesn't appear to be working for fields in a superclass.To Reproduce
yields
{"child-prop":"foo","parent":"foo"}
.Expected behavior
I would expect to see
{"child-prop":"foo","parent-prop":"foo"}
.Versions
Kotlin: 1.5.20
Jackson-module-kotlin: 2.12.3
Jackson-databind: 2.12.3
The text was updated successfully, but these errors were encountered: