{"record":{"id":"e9e680ebc9716ec6","repo":"eclipse-vertx/vert.x","slug":"failed-to-decode-e-getmessage","errorCode":null,"errorMessage":"Failed to decode:${e.getMessage()}","messagePattern":"Failed to decode:(.+?)","errorType":"exception","errorClass":"DecodeException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/json/jackson/DatabindCodec.java","lineNumber":103,"sourceCode":"  }\n\n  @Override\n  public <T> T fromBuffer(Buffer buf, Class<T> clazz) throws DecodeException {\n    return fromParser(createParser(buf), clazz);\n  }\n\n  public <T> T fromBuffer(Buffer buf, TypeReference<T> typeRef) throws DecodeException {\n    return fromParser(createParser(buf), typeRef);\n  }\n\n  @Override\n  public <T> T fromStream(InputStream in, Class<T> clazz) throws DecodeException {\n    try {\n      JsonParser parser = mapper.getFactory().createParser(in);\n      parser.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE);\n      return fromParser(parser, clazz);\n    } catch (IOException e) {\n      throw new DecodeException(\"Failed to decode:\" + e.getMessage(), e);\n    }\n  }\n\n  public static JsonParser createParser(BufferInternal buf) {\n    try {\n      return DatabindCodec.mapper.getFactory().createParser((InputStream) new ByteBufInputStream(buf.getByteBuf()));\n    } catch (IOException e) {\n      throw new DecodeException(\"Failed to decode:\" + e.getMessage(), e);\n    }\n  }\n\n  public static JsonParser createParser(String str) {\n    try {\n      return DatabindCodec.mapper.getFactory().createParser(str);\n    } catch (IOException e) {\n      throw new DecodeException(\"Failed to decode:\" + e.getMessage(), e);\n    }\n  }","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/json/jackson/DatabindCodec.java#L85-L121","documentation":"DatabindCodec.fromStream wraps any IOException raised while creating or reading a Jackson JsonParser from an InputStream into a DecodeException 'Failed to decode:...'. It signals the input stream did not yield parseable JSON.","triggerScenarios":"Json.decodeValue(InputStream) / DatabindCodec.fromStream(clazz) with an empty stream, already-closed stream, malformed JSON, an invalid charset, or an IO error mid-read (network drop, premature EOF).","commonSituations":"Reading a config resource that does not exist on the classpath (stream is empty/null content); passing a response body stream that was already consumed; feeding truncated JSON from a socket.","solutions":["Check getCause() for the underlying IOException message (it names the real problem).","Verify the stream is open and positioned at the start (re-open the resource rather than reusing a consumed stream).","Validate the JSON is well-formed (e.g. dump the bytes first: IOUtils.toString).","Ensure the stream charset is UTF-8 or another JSON-compatible encoding."],"exampleFix":"// before\nInputStream in = socket.getInputStream();\nJson.decodeValue(in, Config.class); // DecodeException on truncated data\n// after\nString text = in.readAllBytes() ... validate;\nif (!text.trim().isEmpty()) {\n  Config c = Json.decodeValue(Buffer.buffer(text), Config.class);\n}","handlingStrategy":"try-catch","validationCode":"if (in == null) throw new IllegalArgumentException(\"input stream is null\");\nif (in.available() == 0 && expectsData) throw new IllegalStateException(\"input stream is empty\");","typeGuard":"static boolean hasReadableData(InputStream in) throws IOException {\n  return in != null && in.read() != -1; // mark/reset to rewind if supported\n}","tryCatchPattern":"try (InputStream in = openStream()) {\n  return Json.decodeValue(in, Config.class);\n} catch (DecodeException e) {\n  throw new ConfigException(\"Cannot parse config: \" + e.getCause().getMessage(), e);\n}","preventionTips":["Use try-with-resources so streams are fresh, open, and closed once.","Never re-consume an exhausted stream; re-open the resource instead.","Prefer decoding from String/Buffer so you can log the exact payload on failure."],"tags":["json","decode","stream","io"],"backgroundTag":"json-decode-failed","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}