{"record":{"id":"3558ccf74b0d4162","repo":"OpenFeign/feign","slug":"type-is-not-a-type-supported-by-this-decoder","errorCode":null,"errorMessage":"{type} is not a type supported by this decoder.","messagePattern":"(.+?) is not a type supported by this decoder\\.","errorType":"exception","errorClass":"DecodeException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/feign/codec/StringDecoder.java","lineNumber":52,"sourceCode":"   */\n  @Override\n  public boolean canDecode(Response response, Type type) {\n    return response.status() == 404\n        || response.status() == 204\n        || response.body() == null\n        || String.class.equals(type);\n  }\n\n  @Override\n  public Object decode(Response response, Type type) throws IOException {\n    Response.Body body = response.body();\n    if (response.status() == 404 || response.status() == 204 || body == null) {\n      return null;\n    }\n    if (String.class.equals(type)) {\n      return Util.toString(body.asReader(response.charset()));\n    }\n    throw new DecodeException(\n        response.status(),\n        format(\"%s is not a type supported by this decoder.\", type),\n        response.request());\n  }\n}\n","sourceCodeStart":34,"sourceCodeEnd":58,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/core/src/main/java/feign/codec/StringDecoder.java#L34-L58","documentation":"StringDecoder only knows how to decode HTTP response bodies into java.lang.String (returning null for 404/204/empty bodies). When handed any other target type it throws this DecodeException, meaning the configured decoder does not support the method's return type. The thrown message names the unsupported type.","triggerScenarios":"Configuring Feign with StringDecoder (directly or via ErrorDecoder/test paths that use it) while an interface method returns a non-String type such as a POJO, Response, Map, or generic type; the call decodes a 2xx non-empty body and then fails the String.class.equals(type) check.","commonSituations":"Using StringDecoder as the only decoder and expecting automatic JSON binding; test harnesses delegating to StringDecoder with non-String expected types; switching a method's return type from String to an object without changing decoders; confusing StringDecoder with Decoder.Default (which handles String and byte[]).","solutions":["Register a decoder matching the return type, e.g. JacksonDecoder/GsonDecoder for POJOs, keeping StringDecoder for String methods via MultiDecoder","Change the interface method's return type to String if you only need the raw body","Use Decoder.Default (or a MultiDecoder chain ending in a default) instead of StringDecoder alone"],"exampleFix":"// before\nFeign.builder().decoder(new StringDecoder()).target(Api.class, url); // method returns User\n// after\nFeign.builder().decoder(new MultiDecoder.Builder()\n    .add(new JacksonDecoder())\n    .add(new StringDecoder())\n    .build()).target(Api.class, url);","handlingStrategy":"type-guard","validationCode":"// ensure decoder supports the method return type before the call\nif (!String.class.equals(returnType)\n    && decoder instanceof feign.codec.StringDecoder) {\n  throw new ConfigurationException(\n      \"StringDecoder cannot decode \" + returnType + \"; register a matching decoder\");\n}","typeGuard":"static boolean stringDecoderSupports(Type type) {\n  return type instanceof Class<?> c && String.class.equals(c);\n}","tryCatchPattern":"try {\n  return api.call();\n} catch (DecodeException e) {\n  if (e.getMessage().endsWith(\"is not a type supported by this decoder.\")) {\n    throw new ClientConfigurationException(\n        \"Return type not supported by configured decoder: \" + e.getMessage(), e);\n  }\n  throw e;\n}","preventionTips":["Only use StringDecoder for methods returning java.lang.String","Use MultiDecoder to pair StringDecoder with a JSON decoder for object types","Prefer Decoder.Default over StringDecoder when you also need byte[] support","Keep interface return types and registered decoders in sync; review on return-type changes"],"tags":["feign","decoding","type-mismatch","stringdecoder"],"backgroundTag":"type-mismatch","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"}