{"record":{"id":"6c18ed6e4d91c928","repo":"OpenFeign/feign","slug":"e-getmessage-6c18ed","errorCode":null,"errorMessage":"${e.getMessage()}","messagePattern":"\\$\\{e\\.getMessage\\(\\)\\}","errorType":"exception","errorClass":"DecodeException","httpStatus":null,"severity":"error","filePath":"jackson/src/main/java/feign/jackson/JacksonIteratorDecoder.java","lineNumber":163,"sourceCode":"      try {\n        JsonToken jsonToken = parser.nextToken();\n        if (jsonToken == null) {\n          return null;\n        }\n\n        if (jsonToken == JsonToken.START_ARRAY) {\n          jsonToken = parser.nextToken();\n        }\n\n        if (jsonToken == JsonToken.END_ARRAY) {\n          ensureClosed(this);\n          return null;\n        }\n\n        return objectReader.readValue(parser);\n      } catch (IOException e) {\n        // Input Stream closed automatically by parser\n        throw new DecodeException(response.status(), e.getMessage(), response.request(), e);\n      }\n    }\n\n    @Override\n    public T next() {\n      if (current != null) {\n        T tmp = current;\n        current = null;\n        return tmp;\n      }\n      T next = readNext();\n      if (next == null) {\n        throw new NoSuchElementException();\n      }\n      return next;\n    }\n\n    @Override","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/jackson/src/main/java/feign/jackson/JacksonIteratorDecoder.java#L145-L181","documentation":"While advancing the iterator, JacksonIteratorDecoder reads the next value with the Jackson ObjectMapper; any IOException during parsing is rethrown as DecodeException carrying the parser's message and the response status. This surfaces malformed JSON or truncated streams mid-iteration rather than at call time.","triggerScenarios":"Iterating a JSON array response where the body is malformed, truncated (connection reset mid-body), not actually a JSON array, or the server returned an error document where elements were expected; readValue fails inside readNext during hasNext()/next().","commonSituations":"Upstream gateway returning HTML error pages with 200; proxies closing connections early; response content-type JSON but body invalid; server-side serialization bug on later array elements.","solutions":["Catch DecodeException around iteration and inspect the cause for the exact parse error and location.","Verify the endpoint actually returns well-formed JSON array content for the whole body.","Check for proxies/gateways truncating responses; enable retries at the client level for transient cuts.","Confirm content-type and that Jackson's ObjectReader config matches the payload structure."],"exampleFix":"// before\ntry (Iterator<User> it = users.iterator()) {\n  while (it.hasNext()) { process(it.next()); } // DecodeException mid-stream\n}\n// after\ntry (Iterator<User> it = users.iterator()) {\n  while (it.hasNext()) {\n    try { process(it.next()); }\n    catch (DecodeException e) { log.error(\"JSON stream failed: {}\", e.getMessage(), e.getCause()); break; }\n  }\n}","handlingStrategy":"try-catch","validationCode":"// before iterating\nif (response.status() != 200) throw new IllegalStateException(\"Non-200: \" + response.status());\n// and confirm Content-Type is JSON\nif (!String.valueOf(response.headers().get(\"content-type\")).contains(\"json\")) {\n  throw new IllegalStateException(\"Response is not JSON\");\n}","typeGuard":null,"tryCatchPattern":"try (Iterator<User> it = users) {\n  while (it.hasNext()) { process(it.next()); }\n} catch (feign.codec.DecodeException e) {\n  logger.error(\"Stream decode failed at status {}: {}\", e.status(), e.getMessage(), e.getCause());\n  // fall back to a full re-fetch with JacksonDecoder if idempotent\n}","preventionTips":["Validate status and content-type before streaming","Only stream from idempotent, trusted endpoints","Watch for gateways/proxies that truncate bodies","Set sane read timeouts so partial bodies fail fast"],"tags":["jackson","json","decode-exception","streaming"],"backgroundTag":"invalid-json-response","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"}