{"record":{"id":"7830348f68bf5559","repo":"eclipse-vertx/vert.x","slug":"failed-to-decode-e-getmessage-783034","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/JacksonCodec.java","lineNumber":141,"sourceCode":"\n  @Override\n  public <T> T fromString(String json, Class<T> clazz) throws DecodeException {\n    return fromParser(createParser(json), clazz);\n  }\n\n  @Override\n  public <T> T fromBuffer(Buffer json, Class<T> clazz) throws DecodeException {\n    return fromParser(createParser(json), clazz);\n  }\n\n  @Override\n  public <T> T fromStream(InputStream in, Class<T> clazz) throws DecodeException {\n    try {\n      JsonParser parser = factory.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  @Override\n  public <T> T fromValue(Object json, Class<T> toValueType) {\n    throw new DecodeException(\"Mapping \" + toValueType.getName() + \"  is not available without Jackson Databind on the classpath\");\n  }\n\n  @Override\n  public String toString(Object object, boolean pretty) throws EncodeException {\n    BufferRecycler br = factory._getBufferRecycler();\n    try (SegmentedStringWriter sw = new SegmentedStringWriter(br)) {\n      JsonGenerator generator = createGenerator(sw, pretty);\n      encodeJson(object, generator);\n      generator.close();\n      return sw.getAndClear();\n    } catch (IOException e) {\n      throw new EncodeException(e.getMessage(), e);","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/json/jackson/JacksonCodec.java#L123-L159","documentation":"Vert.x's JacksonCodec wraps any IOException raised while creating or driving a Jackson JsonParser over an InputStream into a DecodeException with this message. It signals that the JSON input stream could not be parsed (malformed JSON, I/O failure, or encoding problem). The cause retains the original Jackson exception.","triggerScenarios":"Calling JacksonCodec.fromStream(InputStream, Class) (or DatabindCodec's equivalent path) where the stream contains malformed JSON, is closed mid-read, has an invalid encoding, or the underlying InputStream throws an IOException during read.","commonSituations":"Decoding a JSON file or network stream with truncated content; decoding data with a BOM or wrong charset; passing a stream whose source (socket/file) died during read; deserializing into a target class Jackson cannot map when Databind is present but the JSON is invalid.","solutions":["Validate the JSON payload with a parser or linter before decoding","Inspect the cause (DecodeException.getCause()) for the exact Jackson parse error and offset","Ensure the InputStream is fully available and uses a UTF-compatible encoding","If wrapping a socket/file stream, check the source is complete and not closed early"],"exampleFix":"// before\nMyConfig cfg = JacksonCodec.fromStream(in, MyConfig.class); // throws on bad JSON\n// after\ntry {\n  MyConfig cfg = JacksonCodec.fromStream(in, MyConfig.class);\n} catch (DecodeException e) {\n  logger.error(\"Invalid JSON input: \" + e.getCause().getMessage());\n}","handlingStrategy":"try-catch","validationCode":"// Java\npublic static boolean isPlausibleJson(InputStream in) {\n  try {\n    in.mark(1);\n    int c = in.read();\n    in.reset();\n    return c == '{' || c == '[' || c == '\"' || c == '-' || Character.isDigit(c);\n  } catch (IOException e) { return false; }\n}","typeGuard":"public static boolean isJsonStart(String s) {\n  if (s == null) return false;\n  String t = s.stripLeading();\n  return !t.isEmpty() && \"[{\\\"tfn-0\".indexOf(t.charAt(0)) >= 0 || (!t.isEmpty() && Character.isDigit(t.charAt(0)));\n}","tryCatchPattern":"try {\n  T value = JacksonCodec.fromStream(in, T.class);\n} catch (DecodeException e) {\n  // e.getCause() is the Jackson IOException with parse details\n  logger.error(\"JSON decode failed: {}\", e.getCause() != null ? e.getCause().getMessage() : e.getMessage());\n  throw new BadRequestException(\"Malformed JSON payload\");\n}","preventionTips":["Validate payloads as JSON before decoding (schema or parser round-trip)","Keep mark/reset support on streams used for decoding","Always check getCause() to get the exact Jackson parse location","Ensure charset is UTF-8 end-to-end"],"tags":["json","decoding","jackson","stream"],"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"}