{"record":{"id":"7f1129e9703a6780","repo":"apache/druid","slug":"string-cannot-be-deserialized-as-json-to-a-spectat","errorCode":null,"errorMessage":"String cannot be deserialized as JSON to a Spectator Histogram","messagePattern":"String cannot be deserialized as JSON to a Spectator Histogram","errorType":"exception","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"extensions-contrib/spectator-histogram/src/main/java/org/apache/druid/spectator/histogram/SpectatorHistogram.java","lineNumber":174,"sourceCode":"    }\n    if (serializedHistogram instanceof byte[]) {\n      return fromByteBuffer(ByteBuffer.wrap((byte[]) serializedHistogram));\n    }\n    if (serializedHistogram instanceof SpectatorHistogram) {\n      return (SpectatorHistogram) serializedHistogram;\n    }\n    if (serializedHistogram instanceof String) {\n      // Try parse as JSON into HashMap\n      try {\n        HashMap<String, Long> map = JSON_MAPPER.readerFor(HashMap.class).readValue((String) serializedHistogram);\n        SpectatorHistogram histogram = new SpectatorHistogram();\n        for (Map.Entry<String, Long> entry : map.entrySet()) {\n          histogram.add(entry.getKey(), entry.getValue());\n        }\n        return histogram;\n      }\n      catch (JsonProcessingException e) {\n        throw new ParseException((String) serializedHistogram, e, \"String cannot be deserialized as JSON to a Spectator Histogram\");\n      }\n    }\n    if (serializedHistogram instanceof HashMap) {\n      SpectatorHistogram histogram = new SpectatorHistogram();\n      for (Map.Entry<?, ?> entry : ((HashMap<?, ?>) serializedHistogram).entrySet()) {\n        histogram.add(entry.getKey(), (Number) entry.getValue());\n      }\n      return histogram;\n    }\n    throw new ParseException(\n        null,\n        \"Object cannot be deserialized to a Spectator Histogram \"\n        + serializedHistogram.getClass()\n    );\n  }\n\n  @Nullable\n  static SpectatorHistogram fromByteBuffer(ByteBuffer buffer)","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-contrib/spectator-histogram/src/main/java/org/apache/druid/spectator/histogram/SpectatorHistogram.java#L156-L192","documentation":"SpectatorHistogram.deserialize received a String it could not interpret as a SpectatorHistogram. The string is first attempted to be parsed as JSON into a HashMap of counts; if that fails (or the shape is wrong) the deserializer rejects it, because only byte[] serialized histograms, JSON maps, or existing SpectatorHistogram objects are accepted.","triggerScenarios":"Thrown at extensions-contrib/spectator-histogram/src/main/java/org/apache/druid/spectator/histogram/SpectatorHistogram.java:174 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the wrapped JSON parse exception for why the string failed to deserialize.","Ensure histogram values are produced and serialized consistently by SpectatorHistogram/its serializer — do not hand-write serialized values.","Verify no intermediary (e.g. a store or cache) converted the byte[] histogram to a plain string.","If reading from a segment written by an older/incompatible version, re-ingest or upgrade the extension."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}