{"record":{"id":"83213d22fa2410ea","repo":"eclipse-vertx/vert.x","slug":"failed-to-decode-83213d","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":208,"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":190,"sourceCodeEnd":212,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java21/io/vertx/core/json/jackson/v3/DatabindCodec.java#L190-L212","documentation":"DatabindCodec.adapt converts plain Jackson results (LinkedHashMap, ArrayList) into Vert.x JsonObject/JsonArray so decoded values match Vert.x JSON semantics. If any conversion throws (e.g. a map key that is not a String, or nested conversion failure), it is wrapped in DecodeException('Failed to decode: ' + cause message).","triggerScenarios":"Decoding JSON into Object.class (Json.decodeValue(buf)) whose object keys are not Strings — e.g. '{\"1\":2}' is fine, but Jackson maps with non-String keys from custom deserializers; also nested structures failing the cast into JsonObject/JsonArray.","commonSituations":"Decoding to Object and inserting the result into another JsonObject; JSON with numeric-looking keys combined with custom key-type deserializers; programmatic Maps handed through the codec path with mixed key types.","solutions":["Check e.getMessage()/cause to find which value failed conversion.","Ensure JSON object keys are strings — standard JSON guarantees this; fix producers emitting non-string keys via custom serializers.","Decode into a concrete type (Class/TypeReference) instead of Object.class to bypass adapt().","Construct JsonObject/JsonArray manually from the decoded Map/List if custom handling is needed."],"exampleFix":"// before\nObject o = Json.decodeValue(buf); // relies on adapt()\n// after\nMap<String,Object> m = Json.decodeValue(buf, new TypeReference<Map<String,Object>>(){});","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"if (decoded instanceof Map<?,?> m && m.keySet().stream().allMatch(k -> k instanceof String)) {\n  JsonObject o = new JsonObject((Map<String,Object>) m);\n}","tryCatchPattern":"try {\n  Object o = Json.decodeValue(buf);\n} catch (DecodeException e) {\n  log.error(\"adapt() failed: {}\", e.getMessage());\n}","preventionTips":["Prefer decoding into explicit types over Object.class.","Guarantee producers emit string keys (standard JSON).","Insert decoded objects into JsonObject only after confirming JsonObject/JsonArray types."],"tags":["json","decoding","codec","adaptation"],"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"}