{"record":{"id":"8b927aabcfa949e4","repo":"OpenFeign/feign","slug":"e-tostring-8b927a","errorCode":null,"errorMessage":"${e.toString()}","messagePattern":"\\$\\{e\\.toString\\(\\)\\}","errorType":"exception","errorClass":"EncodeException","httpStatus":null,"severity":"error","filePath":"jaxb/src/main/java/feign/jaxb/JAXBEncoder.java","lineNumber":67,"sourceCode":"  private final JAXBContextFactory jaxbContextFactory;\n\n  public JAXBEncoder(JAXBContextFactory jaxbContextFactory) {\n    this.jaxbContextFactory = jaxbContextFactory;\n  }\n\n  @Override\n  public void encode(Object object, Type bodyType, RequestTemplate template) {\n    if (!(bodyType instanceof Class)) {\n      throw new UnsupportedOperationException(\n          \"JAXB only supports encoding raw types. Found \" + bodyType);\n    }\n    try {\n      Marshaller marshaller = jaxbContextFactory.createMarshaller((Class<?>) bodyType);\n      StringWriter stringWriter = new StringWriter();\n      marshaller.marshal(object, stringWriter);\n      template.body(stringWriter.toString());\n    } catch (JAXBException e) {\n      throw new EncodeException(e.toString(), e);\n    }\n  }\n\n  @Override\n  public boolean canEncode(Object object, Type bodyType, RequestTemplate template) {\n    return Util.isXmlContentType(template);\n  }\n}\n","sourceCodeStart":49,"sourceCodeEnd":76,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/jaxb/src/main/java/feign/jaxb/JAXBEncoder.java#L49-L76","documentation":"Same as error 103 in the javax jaxb module: a JAXBException during Marshaller.marshal is converted to EncodeException with e.toString(). Indicates the request object cannot be marshalled to XML, typically due to missing or incorrect JAXB annotations.","triggerScenarios":"encode() with a body object whose class lacks @XmlRootElement, contains un-marshalable fields, or whose class is not registered with the JAXBContextFactory.","commonSituations":"DTOs without JAXB annotations; nested types not annotated; runtime class differing from the declared interface body type.","solutions":["Check getCause() for the exact JAXBException message.","Add @XmlRootElement/@XmlElement annotations or register the class in JAXBContextFactory.Builder.","Confirm the runtime object type matches the declared body type."],"exampleFix":"// before\nclass Payload { private String data; } // marshal fails\n// after\n@XmlRootElement\npublic class Payload { @XmlElement public String data; }","handlingStrategy":"try-catch","validationCode":"// before encoding\nif (!obj.getClass().isAnnotationPresent(XmlRootElement.class)) {\n  throw new IllegalArgumentException(\"request DTO must be @XmlRootElement annotated: \" + obj.getClass());\n}","typeGuard":null,"tryCatchPattern":"try {\n  api.post(payload);\n} catch (EncodeException e) {\n  log.error(\"JAXB marshal failed: {}\", String.valueOf(e.getCause()));\n}","preventionTips":["Annotate all request DTOs and their nested types for JAXB.","Keep declared interface body types consistent with runtime classes.","Unit test encode/decode round trips."],"tags":["jaxb","encode","marshal"],"backgroundTag":"xml-marshal-failed","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"}