{"record":{"id":"6dae42867f7f2b3f","repo":"OpenFeign/feign","slug":"e-getmessage-6dae42","errorCode":null,"errorMessage":"${e.getMessage()}","messagePattern":"\\$\\{e\\.getMessage\\(\\)\\}","errorType":"exception","errorClass":"DecodeException","httpStatus":null,"severity":"error","filePath":"jackson3/src/main/java/feign/jackson3/Jackson3IteratorDecoder.java","lineNumber":170,"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 (JacksonException 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":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/jackson3/src/main/java/feign/jackson3/Jackson3IteratorDecoder.java#L152-L188","documentation":"While pulling the next element from the decoded stream, the Jackson parser throws a JacksonException (malformed JSON, unexpected token, IO problem). Jackson3IteratorDecoder converts it into a Feign DecodeException carrying the HTTP status, the message, the request, and the cause. The underlying input stream is closed by the parser at that point, so iteration cannot continue.","triggerScenarios":"Iterating the Iterator<T> returned from decode() when the response body contains invalid/truncated JSON, a JSON error payload instead of the expected element shape, or the stream is cut off mid-element (proxy timeout, connection reset).","commonSituations":"Server returns an HTML/JSON error page with status 200; NDJSON/streaming endpoints that fail midway; charset mismatches producing corrupt bytes; response body empty except whitespace where a value was expected.","solutions":["Catch feign.DecodeException around iteration and inspect getCause() for the Jackson message and location (line/column)","Verify the endpoint actually streams the expected element JSON (test with curl)","Increase/verify proxy and read timeouts so the body is not truncated mid-stream","Confirm Content-Type and charset match what the server sends","Add a Deserializer/mixin if the element shape differs from the DTO"],"exampleFix":"// before\nIterator<ItemDto> it = itemsApi.stream();\nwhile (it.hasNext()) { save(it.next()); }\n// after\ntry (Iterator<ItemDto> it = itemsApi.stream()) {\n  while (it.hasNext()) {\n    try { save(it.next()); }\n    catch (DecodeException e) { log.error(\"stream broke at element\", e); break; }\n  }\n}","handlingStrategy":"try-catch","validationCode":"// cheap pre-flight before iterating\nif (response.status() != 200) throw new IllegalStateException(\"non-200: \" + response.status());\nString head = peekFirstBytes(response); // must look like '{' or '[' not '<html>'","typeGuard":null,"tryCatchPattern":"try (Iterator<ItemDto> it = decoded) {\n  while (it.hasNext()) {\n    try {\n      process(it.next());\n    } catch (DecodeException e) {\n      log.error(\"Stream decode failed (status {}): {}\", e.status(), e.getCause().getMessage());\n      break; // parser closed the stream; iteration cannot continue\n    }\n  }\n}","preventionTips":["Confirm with curl that the endpoint returns well-formed element JSON for the whole stream","Set adequate read/connect timeouts so large streams are not truncated","Verify Content-Type and charset headers match the actual payload","Handle error pages returned with HTTP 200 before iterating","Keep iterator usage confined (try-with-resources via the decoder's close()) so partial reads are cleaned up"],"tags":["jackson","json","streaming","feign","decoder"],"backgroundTag":"json-unmarshal-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"}