Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

Transient fields serialized when @XmlAccessorType(XmlAccessType.FIELD) is present #61

@dsharp1

Description

@dsharp1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions