OpenFeign/feign · error · UnsupportedOperationException
JAXB only supports encoding raw types. Found
Error message
JAXB only supports encoding raw types. Found ${bodyType} What it means
JAXBEncoder.encode only supports request body types that are plain Classes (JAXB-mappable raw types). If the declared body type is a ParameterizedType such as List<Foo> or Map<String,Foo>, it throws UnsupportedOperationException because JAXB cannot marshal generic types without a root wrapper element.
Solutions
- Encode a single @XmlRootElement-annotated root object instead of a generic collection.
- Introduce a wrapper DTO containing the collection as an @XmlElement field and post that.
- Use a JSON encoder module for generic types and reserve JAXB for raw annotated types.
Example fix
// before
@POST void send(List<Item> items);
// after
@XmlRootElement
class ItemList { @XmlElement(name="item") List<Item> items; }
@POST void send(ItemList items); Defensive patterns
Strategy: type-guard
Validate before calling
// before encoding
if (!(bodyType instanceof Class)) {
throw new IllegalArgumentException("JAXB encoder requires a raw Class body type, got: " + bodyType);
} Type guard
boolean isRawType(java.lang.reflect.Type t) {
return t instanceof Class;
} Try / catch
try {
encoder.encode(obj, type, template);
} catch (UnsupportedOperationException e) {
// switch to a wrapper @XmlRootElement DTO or a JSON encoder
} Prevention
- Only declare raw, JAXB-annotated classes as request bodies when using JAXB.
- Wrap collections in an @XmlRootElement DTO.
- Document that the JAXB module does not handle generic types.
When it happens
Trigger: Declaring a Feign method whose request body is a generic collection or other ParameterizedType while using JAXBEncoder, then invoking encode (via Feign's customEncoder path).
Common situations: Trying to POST a List<MyDto> with JAXB encoding; developers expect automatic collection handling like JSON encoders provide.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- JAXB only supports encoding raw types. Found
- ${e.toString()}
- JAXB only supports decoding raw types. Found
- ${e.toString()}
- is not a type supported by this encoder.
AI-assisted analysis of OpenFeign/feign@e2a1e27560 (2026-09-10).
Data as JSON: /api/errors/1b91a98d3853206b.
Report an issue: GitHub.
Appendix: source
Thrown at jaxb-jakarta/src/main/java/feign/jaxb/JAXBEncoder.java:58
* .encoder(new JAXBEncoder(jaxbFactory))
* .target(MyApi.class, "http://api");
* </pre>
*
* <p>The JAXBContextFactory should be reused across requests as it caches the created JAXB
* contexts.
*/
public class JAXBEncoder implements Encoder, PredicatedEncoder {
private final JAXBContextFactory jaxbContextFactory;
public JAXBEncoder(JAXBContextFactory jaxbContextFactory) {
this.jaxbContextFactory = jaxbContextFactory;
}
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) {
if (!(bodyType instanceof Class)) {
throw new UnsupportedOperationException(
"JAXB only supports encoding raw types. Found " + bodyType);
}
try {
Marshaller marshaller = jaxbContextFactory.createMarshaller((Class<?>) bodyType);
StringWriter stringWriter = new StringWriter();
marshaller.marshal(object, stringWriter);
template.body(stringWriter.toString());
} catch (JAXBException e) {
throw new EncodeException(e.toString(), e);
}
}
@Override
public boolean canEncode(Object object, Type bodyType, RequestTemplate template) {
return Util.isXmlContentType(template);
}
}
View on GitHub (pinned to e2a1e27560)