{"record":{"id":"f41a998dc0fe83fb","repo":"OpenFeign/feign","slug":"jsonexception-getmessage","errorCode":null,"errorMessage":"${jsonException.getMessage()}","messagePattern":"\\$\\{jsonException\\.getMessage\\(\\)\\}","errorType":"exception","errorClass":"DecodeException","httpStatus":null,"severity":"error","filePath":"json/src/main/java/feign/json/JsonDecoder.java","lineNumber":96,"sourceCode":"      bodyReader.reset();\n      return decodeBody(response, type, bodyReader);\n    } catch (JSONException jsonException) {\n      if (jsonException.getCause() != null && jsonException.getCause() instanceof IOException) {\n        throw (IOException) jsonException.getCause();\n      }\n      throw new DecodeException(\n          response.status(), jsonException.getMessage(), response.request(), jsonException);\n    }\n  }\n\n  private Object decodeBody(Response response, Type type, Reader reader) throws IOException {\n    if (String.class.equals(type)) return Util.toString(reader);\n    JSONTokener tokenizer = new JSONTokener(reader);\n    if (Map.class.equals(type)) return new JSONObject(tokenizer).toMap();\n    else if (JSONObject.class.isAssignableFrom((Class<?>) type)) return new JSONObject(tokenizer);\n    else if (JSONArray.class.isAssignableFrom((Class<?>) type)) return new JSONArray(tokenizer);\n    else\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  @Override\n  public Object convert(Object object, Type type) throws IOException {\n    if (type instanceof Class) {\n      Class<?> cls = (Class<?>) type;\n      if (cls == JSONObject.class && object instanceof Map) {\n        return new JSONObject((Map<?, ?>) object);\n      }\n      if (cls == String.class) {\n        return object.toString();\n      }\n    }\n    if (object instanceof Map) {\n      return new JSONObject((Map<?, ?>) object);","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/json/src/main/java/feign/json/JsonDecoder.java#L78-L114","documentation":"JsonDecoder.decodeBody() only supports decoding into String, Map, JSONObject, or JSONArray. For any other target Type it throws a DecodeException stating the type is not supported. This is a capability limitation of the org.json-based decoder, not a data problem.","triggerScenarios":"Declaring a Feign method returning a custom POJO, List<MyPojo>, Optional<X>, or any type other than String/Map/JSONObject/JSONArray while using JsonDecoder as the decoder.","commonSituations":"Swapping Jackson/Gson for JsonDecoder without realizing it has no reflection/data-binding; changing a Feign interface method's return type after switching decoders.","solutions":["Change the Feign method return type to Map<String, Object>, JSONObject, JSONArray, or String","Switch to a data-binding decoder (JacksonDecoder/GsonDecoder) for POJOs","Convert manually: decode to JSONObject/Map and map to your POJO yourself","Wrap with a custom Decoder that delegates to JsonDecoder only for supported types"],"exampleFix":"// before\n@RequestLine(\"GET /users/{id}\") User getUser(String id); // JsonDecoder\n// after\n@RequestLine(\"GET /users/{id}\") Map<String, Object> getUser(String id);\n// or use Feign.builder().decoder(new JacksonDecoder())","handlingStrategy":"type-guard","validationCode":"static boolean jsonDecoderSupported(Type t) {\n  return t == String.class || Map.class.equals(t)\n      || JSONObject.class.isAssignableFrom((Class<?>) t)\n      || JSONArray.class.isAssignableFrom((Class<?>) t);\n}","typeGuard":"boolean ok = jsonDecoderSupported(returnType); if (!ok) useJacksonDecoder();","tryCatchPattern":null,"preventionTips":["Restrict JsonDecoder usage to String/Map/JSONObject/JSONArray return types","Pair JsonDecoder with Jackson/Gson for POJOs via a delegating decoder","Document supported types in your Feign configuration module"],"tags":["json","decoder","unsupported-type","feign"],"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"}