-
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
View inclusion on private fields is not used for inherited fields #620
Comments
Is this Kotlin? If so, I'll need to transfer this to Kotlin module, or, alternatively, if it can be reproduced with plain Java it may remain here. |
This problem is not Kotlin specific. Properties are just a combination of private field and a getter for val and getter+setter for var. In this case the annotation will be added to the private field. I could transfer the code to Java but the general gist is the same. |
Just because the general idea is the same does not necessarily mean this would not be Kotlin-specific (in the sense I meant it), mostly because Kotlin module's handling of (Kotlin) classes differs in some ways from general databind handling of POJOs. So: I can move this to Kotlin module for checking there (which is fine), or, if there is Java-only version that shows the issue without Kotlin module, it can be worked on here. |
Sorry for the long delay. I took a deeper dive into the problem and created a implementation in java: public class Java {
public interface View {}
public static class B {
@JsonView(View.class)
private String b = "b";
public String getB() {
return b;
}
public void setB(String b) {
this.b = b;
}
}
public static class A extends B {
@JsonView(View.class)
private String a = "a";
public String getA() {
return a;
}
public void setA(String a) {
this.a = a;
}
}
public static void main(String[] args) throws JsonProcessingException {
final var mapper = new ObjectMapper().disable(MapperFeature.DEFAULT_VIEW_INCLUSION);
System.out.println(mapper.writerWithView(View.class).writeValueAsString(new A()));
}
} This solution works. It also works if I apply the View annotation to the getter functions in Kotlin so the problem seem to be with inheritence of the View annoation for private fields in Kotlin only. Can this ticket be transfered to the Kotlin module? |
It is closed as a duplicate of #658. |
Describe the bug
Given a class
A
with a private fielda
that extends a classB
with a private fieldb
and both fields having the@JsonView
annotation the annotation of fieldb
is not processed when serializing with a given view.Version information
2.13.3
To Reproduce
Expected behavior
Serialized output is {"a": "a", "b": "b"} but is {"a": "a"}
Additional context
The text was updated successfully, but these errors were encountered: