{"record":{"id":"3164a04c7d53d1df","repo":"eclipse-vertx/vert.x","slug":"failed-to-decode-3164a0","errorCode":null,"errorMessage":"Failed to decode:","messagePattern":"Failed to decode:","errorType":"exception","errorClass":"DecodeException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java21/io/vertx/core/json/jackson/v3/DatabindCodec.java","lineNumber":109,"sourceCode":"    return fromParser(mapper.reader().without(StreamReadFeature.AUTO_CLOSE_SOURCE).createParser(in), clazz);\n  }\n\n  public static JsonParser createParser(BufferInternal buf) {\n    return DatabindCodec.mapper.createParser((InputStream) new ByteBufInputStream(buf.getByteBuf()));\n  }\n\n  public static JsonParser createParser(String str) {\n    return DatabindCodec.mapper.createParser(str);\n  }\n\n  public static <T> T fromParser(JsonParser parser, Class<T> type) throws DecodeException {\n    T value;\n    JsonToken remaining;\n    try {\n      value = DatabindCodec.mapper.readValue(parser, type);\n      remaining = parser.nextToken();\n    } catch (Exception e) {\n      throw new DecodeException(\"Failed to decode:\" + e.getMessage(), e);\n    } finally {\n      close(parser);\n    }\n    if (remaining != null) {\n      throw new DecodeException(\"Unexpected trailing token\");\n    }\n    if (type == Object.class) {\n      value = (T) adapt(value);\n    }\n    return value;\n  }\n\n  private static <T> T fromParser(JsonParser parser, TypeReference<T> type) throws DecodeException {\n    T value;\n    try {\n      value = DatabindCodec.mapper.readValue(parser, type);\n    } catch (Exception e) {\n      throw new DecodeException(\"Failed to decode:\" + e.getMessage(), e);","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java21/io/vertx/core/json/jackson/v3/DatabindCodec.java#L91-L127","documentation":"DatabindCodec.fromParser delegates JSON parsing to the Jackson ObjectMapper (mapper.readValue(parser, type)). Any exception thrown during databinding (malformed JSON, type coercion failure, wrapped custom exceptions) is caught and rethrown as a Vert.x DecodeException with message 'Failed to decode:' plus the underlying cause message. The original exception is preserved as the cause.","triggerScenarios":"Calling Json.decodeValue(buffer/string, Class) or DatabindCodec.fromValue/fromParser with input that Jackson cannot bind: malformed JSON syntax, wrong target type (e.g. decoding a JSON array into a POJO), or a deserializer that throws (like the base64 error).","commonSituations":"Decoding an empty or truncated payload from an HTTP body or Kafka message; a service contract change where the sender emits arrays but the receiver expects an object; decoding '{\"n\":1}x' with trailing garbage (Jackson fails or the trailing-token check fires).","solutions":["Inspect e.getCause() (the wrapped Jackson exception) — it pinpoints the parse/coercion problem and its JSON location.","Validate that the payload is complete, non-empty, and well-formed JSON before decoding.","Check the target type matches the JSON shape (object vs array vs primitive); use the correct Class/TypeReference.","If a custom deserializer threw, fix the data or that deserializer (e.g. invalid Base64)."],"exampleFix":"// before\nMyType v = Json.decodeValue(body, MyType.class); // throws on bad payload\n// after\ntry {\n  MyType v = Json.decodeValue(body, MyType.class);\n} catch (DecodeException e) {\n  logger.warn(\"Bad payload: {}\", e.getCause() != null ? e.getCause().getMessage() : e.getMessage());\n}","handlingStrategy":"try-catch","validationCode":"boolean looksLikeJson(String s) {\n  String t = s == null ? \"\" : s.trim();\n  return !t.isEmpty() && ((t.charAt(0) == '{' && t.endsWith(\"}\")) || (t.charAt(0) == '[' && t.endsWith(\"]\")));\n}","typeGuard":null,"tryCatchPattern":"try {\n  MyType v = Json.decodeValue(payload, MyType.class);\n} catch (DecodeException e) {\n  Throwable cause = e.getCause();\n  log.error(\"Decode failed: {}\", cause != null ? cause.getMessage() : e.getMessage());\n  return Result.badRequest(\"malformed payload\");\n}","preventionTips":["Check payload is non-empty and complete before decoding.","Match the target Class/TypeReference to the actual JSON shape.","Log the cause, not just the wrapper message, when debugging."],"tags":["json","decoding","jackson","codec"],"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-14T00:17:10.932Z"}