-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Problem with multi-argument Creator with @JsonBackReference
property
#1516
Comments
Yes, sounds like a bug. Thank you for thorough investigation and notes. I haven't had to look into this one but hope to address it. |
Thanks for the reply, would greatly appreciate further investigation into this issue and a fix (if any). |
So, is it a confirmed bug? |
@wheredevel I have not had time to look further, but sounds like legit bug. |
Alas test uses Lombok. This is problematic as I do not have (nor plan to) install Lombok, as it does not (unlike most other libraries) work using just basic build tools and IDE. |
... that aside I do appreciate reproductions, which are greatly appreciated! :-D |
Unfortunately I am unable to reproduce the issue at this point. Another thing to know is that So, what I would need at this point is reproduction with explicitly defined setters/getters/constructors, with appropriate annotations. I assume Lombok gives access to generated source code, or allows sources to be generated for troubleshooting? |
…al where lombok generates constructors (I think)
Ok, I'll look at that tomorrow and see if we can reproduce without lombok. Thanks. |
@cowtowncoder Lombok works with any Java IDE.
Or follow installation instructions. One more thing is to include the jar in your build, so that
|
@wheredevel I know it is possible, but I do not want to install jars for arbitrary frameworks in my classpath. This is why from this point on no Lombok dependencies are to be added for any of Jackson projects: if I did, then everyone everywhere would have to do same installation just to build Jackson. |
I tested some different configurations and found that you were correct, the code in my repo works with Lombok removed. So I dug a bit more and found that it only fails when the child is annotated with @AllArgsConstructor. The parent can have it and it works just fine. I've branched myh repo and changed it so it passes while using lombok. The link shows the specific annotation that is causing the problem. Seems like I probably need to dig a bit more and maybe file a bug with lombok. Thanks for the help. |
@atribe Thank you for digging this up. Just one follow-up question: do you know what One other note: code sample is using back references ( |
@shongywong If you are also using Lombok, you probably will need to avoid I will see if I can construct a non-Lombok test case with this information. |
@shongywong could you elaborate more on this, please? Because, I use both annotations, and got the error. |
@cowtowncoder This is the decompiled ChildObject class with
|
@atribe Thank you! Without having tested this, I think the problem really isn't Lombok, but combination of just two things:
I think this should finally allow me to create test to see how to address this problem. |
In the meantime: couple of work-arounds that do exist:
either of which would work around the issue. |
@JsonBackReference
property
Ok I can now reproduce the issue as reported. |
So: for 2.8(.8) I am only able to improve error messaging -- passing of |
…OJO that needs no buffering (no creator)
Data point: I think I managed to avoid this bug by adding |
@joshwand Thanks! That makes sense, that would also prevent auto-discovery of creators. |
@cowtowncoder @joshwand We have faced the same issue and we found another possible workaround. If you are only using @AllArgsConstructor for internal use in the class (for @builder as instance), you can define the constructor private like this "@AllArgsConstructor(access = AccessLevel.PRIVATE)" |
Yet another workaround: |
As Full lombok.config in the root of our parent project:
|
Last lombok version v1.16.20 (January 9th, 2018) introduced a breaking change:
So, But for me it caused another problem: now Jackson cannot deserialize So I have to add this |
Is the |
Yes, that is related: disabling of that feature prevents use of |
For the error, please refer to this github example for a consistent repro: https://github.com/atribe/ReproducingBug
The short summary of the issue is that Jackson 2.7.+ - 2.8.6 is not correctly setting up the setter methods for properties defined in my class that I want to deserialize when those classes have managed/back references. Also, another issue is that @JsonProperty and @JsonSetter annotation is ignored, so there isn't a way to explicitly provide your own setter methods for the properties.
Below is the trace of debugging I have done on this issue.
I have a simple JSON file that shows a ParentObject and a ChildObject. The ParentObject has a managed reference that is a list of its children. The ChildObject has a back reference to its parent object.
In Jackson 2.6.7, when I run the deserializer for these objects, it will properly handle the references and generating mutators for those properties that have dependencies.
In Jackson 2.7.0 - 2.8.6, when I run the deserializer on the same code, it will fail with the error below if I use the managed/back reference annotation. When that managed/back annotation is removed, it will run just fine.
From the stacktrace, I found that when it sets up the managed/back references there is this code below in BeanDeserializerFactory.java. The line of interest is when it calls construct in the SimpleBeanPropertyDefinition
The method call has this code from SimpleBeanPropertyDefinition.java, where it calls member.getName():
member.getName() returns an empty string every single time (that is the current implementation and has been that way for years). Now after this member is instantiated, there is this call where the AnnotatedMember mutator variable is not correctly created:
If you go to the method propDef.getNonConstructorMutator(), the implementation is below:
Go to getSetter() and this is the implementation below. The _member variable is always false and returns null.
When we bubble back up to the original caller in constructSettableProperty, it will be null and throw the error even if you explicitly write out a setter method associated with your property that has a managed/back reference.
The text was updated successfully, but these errors were encountered: