OpenFeign/feign · error · UnsupportedOperationException

SOAP only supports encoding raw types. Found

Error message

SOAP only supports encoding raw types. Found %s

What it means

The jakarta SOAP encoder marshals request objects with JAXB, which requires the body type to be a raw Class so createMarshaller((Class<?>) bodyType) can be called. If the declared body type is not a Class (e.g. a generic type variable, ParameterizedType not unwrapped, or wildcard), encode() throws UnsupportedOperationException before any marshalling happens.

Solutions

  1. Declare the request parameter as a concrete raw class (e.g. OrderRequest) instead of a generic type.
  2. Provide a custom Encoder that resolves the generic type to a concrete class and delegates to SOAPEncoder.
  3. If wrapping is needed, encode the inner concrete object directly rather than the wrapper.

Example fix

// before
@Post void submit(T body);
// after
@Post void submit(OrderRequest body);
Defensive patterns

Strategy: type-guard

Validate before calling

static boolean isSoapEncodable(Type type) { return type instanceof Class; }

Type guard

if (!isSoapEncodable(bodyType)) {
  throw new IllegalArgumentException("SOAP request body must be a concrete class");
}

Try / catch

try {
  client.submit(request);
} catch (UnsupportedOperationException e) {
  if (e.getMessage() != null && e.getMessage().contains("SOAP only supports encoding raw types")) {
    // change the @Body parameter to a concrete class
  }
  throw e;
}

Prevention

When it happens

Trigger: Declaring a Feign @Body/parameter type that is not a concrete class — a type variable T, a wildcard, or an exotic Type — and invoking the method so encode() is called on the request object.

Common situations: Generic client interfaces parameterized on the request body type; wrapping request payloads in custom generic types and expecting the SOAP encoder to introspect them.

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


AI-assisted analysis of OpenFeign/feign@e2a1e27560 (2026-09-10). Data as JSON: /api/errors/4d9d5026d48da134. Report an issue: GitHub.

Appendix: source

Thrown at soap-jakarta/src/main/java/feign/soap/SOAPEncoder.java:112

    this.jaxbContextFactory = builder.jaxbContextFactory;
    this.writeXmlDeclaration = builder.writeXmlDeclaration;
    this.charsetEncoding = builder.charsetEncoding;
    this.soapProtocol = builder.soapProtocol;
    this.formattedOutput = builder.formattedOutput;
  }

  public SOAPEncoder(JAXBContextFactory jaxbContextFactory) {
    this.jaxbContextFactory = jaxbContextFactory;
    this.writeXmlDeclaration = true;
    this.formattedOutput = false;
    this.charsetEncoding = StandardCharsets.UTF_8;
    this.soapProtocol = DEFAULT_SOAP_PROTOCOL;
  }

  @Override
  public void encode(Object object, Type bodyType, RequestTemplate template) {
    if (!(bodyType instanceof Class)) {
      throw new UnsupportedOperationException(
          "SOAP only supports encoding raw types. Found " + bodyType);
    }
    try {
      Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
      Marshaller marshaller = jaxbContextFactory.createMarshaller((Class<?>) bodyType);
      marshaller.marshal(object, document);
      SOAPMessage soapMessage = MessageFactory.newInstance(soapProtocol).createMessage();
      soapMessage.setProperty(
          SOAPMessage.WRITE_XML_DECLARATION, Boolean.toString(writeXmlDeclaration));
      soapMessage.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, charsetEncoding.displayName());
      soapMessage.getSOAPBody().addDocument(document);

      soapMessage = modifySOAPMessage(soapMessage);

      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      if (formattedOutput) {
        Transformer t = TransformerFactory.newInstance().newTransformer();
        t.setOutputProperty(OutputKeys.INDENT, "yes");

View on GitHub (pinned to e2a1e27560)