-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Description
Affects: <Spring Framework version>
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 #30552 provides support on serialization process.
Thanks for your help