-
Notifications
You must be signed in to change notification settings - Fork 20
Transient fields serialized when @XmlAccessorType(XmlAccessType.FIELD) is present #61
Comments
The changed that exposed this issue was made a couple months ago in POJOPropertiesCollector. The check for hasName is true since USE_DEFAULT is an empty string.
|
Thank you for reporting this. I hope to look into it soon. |
Unfortunately I can not reproduce this locally with JSON output, with version 2.8.1, using classes shown in |
I am not sure why that would be. The issue occurs for me in 2.8.1, 2.8.2-SNAPSHOT, and 2.8.3-SNAPSHOT. Let me detail my steps a little further and maybe you can compare against the steps that you performed.
If I run the same test in the jackson-dataformat-xml project, I do not need to add the extra dependency, and the result is the same. |
I added an assertion to the code to see if that makes a difference for you when you run it. Also, I am attaching the pom.xml with the dependency required to run this. |
jaxb-annotations-bug-61.zip is a simple example to reproduce the problem with Jackson 2.8.1. Simply unzip and run mvn test and see the failure. If you set the jacksonVersion property to 2.7.6 in pom.xml and re-run the test, you will see that the test works properly. |
Any idea when you might have time to review Derek's proposed fix. This regression is preventing us from uptaking Jackson 2.8+. Thanks! |
@rpatrick00 I haven't had time to look into this. From above I am not 100% what the suggested fix is, although as it is related to name handling of JAXB module, perhaps it can be handled here, locally. |
Downloaded zip, can reproduce the failure now. |
Looks like this has to do with auto-detection; should not see the getter... |
Whatever it is, this change caused the regression. I hope you are able to find a fix... |
Ok. This was bit tricky to resolve, as the change in databind exposed a problem more so than strictly causing it... problem being that Thank you for the test case & follow up -- this will be in 2.8.3 patch. |
Thanks! I didn't look as closely at the code as Derek did but it seems like the tests for jaxb annotations directly on the field (to overrides the visibility) is picking up the class-level @XmlAccessorType(XmlAccessType.FIELD) when it shouldn't. In my opinion, a class-level annotation that applies to the field should not be considered when overriding the visibility... |
@rpatrick00 Class-level visibility only defines visibility for auto-detection, and explicit annotations can further make it certain (inclusion) or remove (exclusion). So case FIELD: // all fields, independent of visibility; no methods
return checker.withFieldVisibility(Visibility.ANY)
.withSetterVisibility(Visibility.NONE)
.withGetterVisibility(Visibility.NONE)
.withIsGetterVisibility(Visibility.NONE) so yes, modifiers on member itself should override class or global defaults. At any rate, please let me know if things do (or do not) work after fix included in 2.8 branch (for 2.8.3). |
Your change fixed my issue, thank you. |
private transient fields are serialized when the class is annotated with XmlAccessType.FIELD.
The cause is related to the way that the _addFields method in POJOPropertiesCollector determines if the field should be skipped. If the field is transient AND the field name is null (where the field name is determined by XmlElement, XmlElementWrapper, etc), the field is marked as not visible and gets skipped.
When the isVisible method in JaxbAnnotationIntrospector returns true if the annotated class has a XmlAccessType.FIELD class annotation, this causes the name to be returned as PropertyName.USE_DEFAULT instead of null. This means that the name is not null (its and empty string) when _addFields method checks the transient field and therefore it does not check if the field is transient.
The attached unit test demonstrates the use case and results in a stackoverflow due to infinite recursion. Removing the @XmlAccessorType(XmlAccessType.FIELD) will allow the test to run without an error.
simple.zip
The text was updated successfully, but these errors were encountered: