{"record":{"id":"11d0a4a4090abdd6","repo":"OpenFeign/feign","slug":"jaxb-only-supports-decoding-raw-types-found-typ-11d0a4","errorCode":null,"errorMessage":"JAXB only supports decoding raw types. Found ${type}","messagePattern":"JAXB only supports decoding raw types\\. Found (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"jaxb/src/main/java/feign/jaxb/JAXBDecoder.java","lineNumber":76,"sourceCode":"    this.jaxbContextFactory = jaxbContextFactory;\n    this.namespaceAware = true;\n  }\n\n  private JAXBDecoder(Builder builder) {\n    this.jaxbContextFactory = builder.jaxbContextFactory;\n    this.namespaceAware = builder.namespaceAware;\n  }\n\n  @Override\n  public Object decode(Response response, Type type) throws IOException {\n    if (response.status() == 404 || response.status() == 204) return Util.emptyValueOf(type);\n    if (response.body() == null) return null;\n    while (type instanceof ParameterizedType) {\n      ParameterizedType ptype = (ParameterizedType) type;\n      type = ptype.getRawType();\n    }\n    if (!(type instanceof Class)) {\n      throw new UnsupportedOperationException(\n          \"JAXB only supports decoding raw types. Found \" + type);\n    }\n\n    try {\n      SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();\n      /* Explicitly control sax configuration to prevent XXE attacks */\n      saxParserFactory.setFeature(\"http://xml.org/sax/features/external-general-entities\", false);\n      saxParserFactory.setFeature(\"http://xml.org/sax/features/external-parameter-entities\", false);\n      saxParserFactory.setFeature(\"http://apache.org/xml/features/disallow-doctype-decl\", false);\n      saxParserFactory.setFeature(\n          \"http://apache.org/xml/features/nonvalidating/load-external-dtd\", false);\n      saxParserFactory.setNamespaceAware(namespaceAware);\n\n      return jaxbContextFactory\n          .createUnmarshaller((Class<?>) type)\n          .unmarshal(\n              new SAXSource(\n                  saxParserFactory.newSAXParser().getXMLReader(),","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/jaxb/src/main/java/feign/jaxb/JAXBDecoder.java#L58-L94","documentation":"The javax-based jaxb module's JAXBDecoder.decode unwraps ParameterizedTypes and then requires the resulting type to be a plain Class; otherwise it throws UnsupportedOperationException, because JAXB can only decode into raw JAXB-annotated classes.","triggerScenarios":"Declaring a Feign method whose return type reduces to a non-Class (e.g. a generic wrapper that survives unwrapping, or using a raw collection type that JAXB cannot bind) with a JAXBDecoder.","commonSituations":"Using generic or wrapper return types with JAXB decoding, which JAXB cannot represent without an annotated root wrapper class.","solutions":["Return a raw JAXB-annotated class instead of a generic type.","Wrap collections in an @XmlRootElement wrapper DTO.","Switch to a JSON decoder module for generic return types."],"exampleFix":"// before\nList<Item> list();\n// after\n@XmlRootElement\nclass ItemList { @XmlElement(name=\"item\") List<Item> items; }\nItemList list();","handlingStrategy":"type-guard","validationCode":"// before declaring/calling\ntypeCheck(methodReturnType);","typeGuard":"boolean isJaxbDecodable(java.lang.reflect.Type t) {\n  while (t instanceof ParameterizedType) {\n    t = ((ParameterizedType) t).getRawType();\n  }\n  return t instanceof Class;\n}","tryCatchPattern":"try {\n  dto = api.call();\n} catch (UnsupportedOperationException e) {\n  // change the return type to a raw JAXB class or switch decoder\n}","preventionTips":["Declare only raw JAXB-annotated return types with JAXBDecoder.","Use wrapper classes for collections.","Use JSON modules for generic return types."],"tags":["jaxb","decode","unsupported-type"],"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"}