{"record":{"id":"3029b4578edd8dbf","repo":"eclipse-vertx/vert.x","slug":"failed-to-decode-e-getmessage-3029b4","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":235,"sourceCode":"        .writeValue(writer, object);\n    } catch (Exception e) {\n      throw new EncodeException(\"Failed to encode as JSON: \" + e.getMessage());\n    }\n  }\n\n  private static Object adapt(Object o) {\n    try {\n      if (o instanceof List) {\n        List list = (List) o;\n        return new JsonArray(list);\n      } else if (o instanceof Map) {\n        @SuppressWarnings(\"unchecked\")\n        Map<String, Object> map = (Map<String, Object>) o;\n        return new JsonObject(map);\n      }\n      return o;\n    } catch (Exception e) {\n      throw new DecodeException(\"Failed to decode: \" + e.getMessage());\n    }\n  }\n}\n","sourceCodeStart":217,"sourceCodeEnd":239,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/json/jackson/DatabindCodec.java#L217-L239","documentation":"The private adapt() method converts Jackson-produced List/Map values into Vert.x JsonArray/JsonObject after decoding; any exception during that adaptation is wrapped in DecodeException. It is invoked from fromValue and fromParser, so a decode that cannot be mapped to Vert.x JSON types surfaces here.","triggerScenarios":"Decoding JSON whose resulting Map keys or values cannot be adapted, or a Map constructor of JsonObject throwing (e.g. null key in the map); also any exception thrown inside adapt's List/Map conversion.","commonSituations":"Decoding JSON with duplicate or unusual keys; custom deserializers producing maps with null keys; using fromParser pipelines where intermediate values are not plain List/Map types.","solutions":["Inspect the cause message to find which value could not be adapted","Sanitize decoded maps (no null keys) before they reach JsonObject construction","Decode to a plain type (Map/List) with Jackson directly if Vert.x JSON wrappers are not required","Catch DecodeException around fromParser/fromValue for untrusted inputs"],"exampleFix":"// before\nObject o = DatabindCodec.fromParser(parser, null); // DecodeException from adapt\n// after\ntry {\n  Object o = DatabindCodec.fromParser(parser, null);\n} catch (DecodeException e) {\n  log.warn(\"unadaptable json payload\", e);\n}","handlingStrategy":"try-catch","validationCode":"try {\n  Object o = Json.decodeValue(json);\n} catch (DecodeException e) {\n  // also covers adapt() failures\n}","typeGuard":"if (decoded instanceof JsonObject || decoded instanceof JsonArray || decoded instanceof Map || decoded instanceof List) { /* adaptable shapes */ }","tryCatchPattern":"try {\n  Object o = DatabindCodec.fromParser(parser, null);\n} catch (DecodeException e) {\n  log.warn(\"payload could not be adapted to Vert.x JSON: {}\", e.getMessage());\n}","preventionTips":["Ensure decoded maps contain no null keys before JsonObject wrapping","Custom deserializers should return plain List/Map/POJO values","Wrap all fromParser/fromValue calls for external input in try-catch"],"tags":["json","deserialization","decode","vertx"],"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"}