{"record":{"id":"4d9d5026d48da134","repo":"OpenFeign/feign","slug":"soap-only-supports-encoding-raw-types-found-s","errorCode":null,"errorMessage":"SOAP only supports encoding raw types. Found %s","messagePattern":"SOAP only supports encoding raw types\\. Found (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"soap-jakarta/src/main/java/feign/soap/SOAPEncoder.java","lineNumber":112,"sourceCode":"    this.jaxbContextFactory = builder.jaxbContextFactory;\n    this.writeXmlDeclaration = builder.writeXmlDeclaration;\n    this.charsetEncoding = builder.charsetEncoding;\n    this.soapProtocol = builder.soapProtocol;\n    this.formattedOutput = builder.formattedOutput;\n  }\n\n  public SOAPEncoder(JAXBContextFactory jaxbContextFactory) {\n    this.jaxbContextFactory = jaxbContextFactory;\n    this.writeXmlDeclaration = true;\n    this.formattedOutput = false;\n    this.charsetEncoding = StandardCharsets.UTF_8;\n    this.soapProtocol = DEFAULT_SOAP_PROTOCOL;\n  }\n\n  @Override\n  public void encode(Object object, Type bodyType, RequestTemplate template) {\n    if (!(bodyType instanceof Class)) {\n      throw new UnsupportedOperationException(\n          \"SOAP only supports encoding raw types. Found \" + bodyType);\n    }\n    try {\n      Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();\n      Marshaller marshaller = jaxbContextFactory.createMarshaller((Class<?>) bodyType);\n      marshaller.marshal(object, document);\n      SOAPMessage soapMessage = MessageFactory.newInstance(soapProtocol).createMessage();\n      soapMessage.setProperty(\n          SOAPMessage.WRITE_XML_DECLARATION, Boolean.toString(writeXmlDeclaration));\n      soapMessage.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, charsetEncoding.displayName());\n      soapMessage.getSOAPBody().addDocument(document);\n\n      soapMessage = modifySOAPMessage(soapMessage);\n\n      ByteArrayOutputStream bos = new ByteArrayOutputStream();\n      if (formattedOutput) {\n        Transformer t = TransformerFactory.newInstance().newTransformer();\n        t.setOutputProperty(OutputKeys.INDENT, \"yes\");","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/soap-jakarta/src/main/java/feign/soap/SOAPEncoder.java#L94-L130","documentation":"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.","triggerScenarios":"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.","commonSituations":"Generic client interfaces parameterized on the request body type; wrapping request payloads in custom generic types and expecting the SOAP encoder to introspect them.","solutions":["Declare the request parameter as a concrete raw class (e.g. OrderRequest) instead of a generic type.","Provide a custom Encoder that resolves the generic type to a concrete class and delegates to SOAPEncoder.","If wrapping is needed, encode the inner concrete object directly rather than the wrapper."],"exampleFix":"// before\n@Post void submit(T body);\n// after\n@Post void submit(OrderRequest body);","handlingStrategy":"type-guard","validationCode":"static boolean isSoapEncodable(Type type) { return type instanceof Class; }","typeGuard":"if (!isSoapEncodable(bodyType)) {\n  throw new IllegalArgumentException(\"SOAP request body must be a concrete class\");\n}","tryCatchPattern":"try {\n  client.submit(request);\n} catch (UnsupportedOperationException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"SOAP only supports encoding raw types\")) {\n    // change the @Body parameter to a concrete class\n  }\n  throw e;\n}","preventionTips":["Declare SOAP request parameters as concrete classes only.","Avoid generic wrapper DTOs for SOAP request bodies.","Review Feign interfaces in code review for non-Class body types."],"tags":["soap","jaxb","generics","encoder","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"e2a1e27560a1e68840c34f031afca88b36096e30","analyzedAt":"2026-09-10T12:37:37.238Z","contentChangedAt":"2026-09-10T12:37:37.238Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}