Skip to content
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

jackson-module-jaxb-annotations: can't use both @XmlElementWrapper and @XmlElement #213

Open
alexlitovsky opened this issue Jul 12, 2023 · 0 comments

Comments

@alexlitovsky
Copy link

alexlitovsky commented Jul 12, 2023

Migrating an application from resteasy-jettison-provider to resteasy-jackson2-provider, but need to retain the JSON format. Can't configure JaxbAnnotationIntrospector to properly handle the case of @XmlElementWrapper + @XmlElement together. Depending on MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME, it either uses one or the other, but not both. Jettison's default behavior is to use both.

Example:

@XmlRootElement(name = "Parent")
public class Parent {

	private List<Child> children = new LinkedList<>();

	@XmlElementWrapper(name = "Children")
	@XmlElement(name = "Child")
	public List<Child> getChildren() {
		return children;
	}

	public void setChildren(List<Child> children) {
		this.children = children;
	}
}

Using Jettison:

{"Parent":{"Children":{"Child":[{"Value":1},{"Value":2}]}}}

Using JaxbAnnotationIntrospector with MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME enabled:

{"Parent":{"Children":[{"Value":"1"},{"Value":"2"}]}}

Using JaxbAnnotationIntrospector with MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME disabled:

{"Parent":{"Child":[{"Value":"1"},{"Value":"2"}]}}

Test:
https://bitbucket.org/alexlitovsky1/jaxb-annotations-bug/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant