Affects: \
Spring boot: 3.3.0
I'm trying to use WebClient
to send XML date using Jaxb.
I have generate my classes using jaxb2-maven-plugin
it seems that this plugin don't add @XmlRootElement
on classes.
Without this annotation the Jaxb marshaler don't want to serialize my data with this error impossible to serialize type “xxxxxx” as an element, as it has no @XmlRootElement annotation
.
The other way to serialize data is to use JAXBElement
, but the JAXBElement
is not supported by Jaxb2XmlEncoder
, the can encode method say:
if (super.canEncode(elementType, mimeType)) {
Class<?> outputClass = elementType.toClass();
return (outputClass.isAnnotationPresent(XmlRootElement.class) ||
outputClass.isAnnotationPresent(XmlType.class));
}
else {
return false;
}
to work properly, I have create a customer encoder with this code:
public class CustomXmlEncoder extends Jaxb2XmlEncoder {
@Override
public boolean canEncode(ResolvableType elementType, MimeType mimeType) {
if (elementType.isAssignableFrom(JAXBElement.class)) {
return true;
}
return super.canEncode(elementType, mimeType);
}
}
I don't know is there is a reason to not support JAXBElement
while this issue https://github.com/spring-projects/spring-framework/issues/30552 provides support on serialization process.
Thanks for your help
Comment From: deblockt
A project to reproduce the issue has been created here: spring-jaxb-error-main.zip
Comment From: sbrannen
Hi @deblockt,
Thanks for raising the issue.
Please note, however that there is no need to create an issue and subsequently a PR for that issue.
In light of that, I am closing this issue as:
- superseded by PR #32977