{"record":{"id":"92d678723936ea42","repo":"apache/druid","slug":"invalid-json-inside-unknown-key","errorCode":null,"errorMessage":"Invalid JSON inside unknown key: ","messagePattern":"Invalid JSON inside unknown key: ","errorType":"exception","errorClass":"JsonMappingException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/context/ResponseContextDeserializer.java","lineNumber":98,"sourceCode":"\n  /**\n   * Skip over a single JSON value: scalar or composite.\n   */\n  private void skipValue(final JsonParser jp, String key) throws IOException\n  {\n    final JsonToken token = jp.currentToken();\n    switch (token) {\n      case START_OBJECT:\n        skipTo(jp, JsonToken.END_OBJECT);\n        break;\n      case START_ARRAY:\n        skipTo(jp, JsonToken.END_ARRAY);\n        break;\n      default:\n        if (token.isScalarValue()) {\n          return;\n        }\n        throw new JsonMappingException(jp, \"Invalid JSON inside unknown key: \" + key);\n    }\n  }\n\n  /**\n   * Freewheel over the contents of a structured object, including any\n   * nested structured objects, until the given end token.\n   */\n  private void skipTo(final JsonParser jp, JsonToken end) throws IOException\n  {\n    while (true) {\n      jp.nextToken();\n      final JsonToken token = jp.currentToken();\n      if (token == null) {\n        throw new JsonMappingException(jp, \"Premature EOF\");\n      }\n      switch (token) {\n        case START_OBJECT:\n          skipTo(jp, JsonToken.END_OBJECT);","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/context/ResponseContextDeserializer.java#L80-L116","documentation":"ResponseContextDeserializer.skipValue throws JsonMappingException when it encounters structured JSON (non-scalar, and not START_OBJECT/START_ARRAY per its switch) inside a value for an unknown response-context key while deserializing the response context header. It means the header contained JSON it could not safely skip or interpret.","triggerScenarios":"Deserializing a Base64/JSON-encoded ResponseContext (e.g. the X-Druid-Response-Context header) that contains an unknown key whose value is a structured token the deserializer's skip logic doesn't recognize.","commonSituations":"Cluster version skew where a newer node emits new response-context key types an older deserializer doesn't know; corrupted or hand-edited response context headers; proxy layers rewriting header values.","solutions":["Align Druid versions across the cluster so all nodes understand the same response-context keys","Inspect the raw header value to find the offending unknown key and its malformed JSON","Remove or fix the unknown key from the serialized context","If writing custom deserialization, extend skipValue to handle the new token type"],"exampleFix":"// before\nthrow new JsonMappingException(jp, \"Invalid JSON inside unknown key: \" + key);\n// after\nif (token.isStructStart()) { skipTo(jp, token == JsonToken.START_OBJECT ? JsonToken.END_OBJECT : JsonToken.END_ARRAY); return; }\nthrow new JsonMappingException(jp, \"Invalid JSON inside unknown key: \" + key);","handlingStrategy":"try-catch","validationCode":"// validate header JSON shape before deserializing\nJsonNode n = mapper.readTree(headerValue);\nif (!n.isObject()) { throw new IllegalArgumentException(\"response context must be a JSON object\"); }","typeGuard":null,"tryCatchPattern":"try { rc = mapper.readValue(headerValue, ResponseContext.class); } catch (JsonMappingException e) { log.warn(e, \"invalid response context\"); rc = ResponseContext.createEmpty(); }","preventionTips":["Keep Druid versions consistent across the cluster","Validate/quote headers through proxies carefully","Test deserialization of all keys your deployment emits"],"tags":["jackson","json","deserialization","response-context"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}