apache/druid · error · ParseException
String cannot be deserialized as JSON to a Spectator…
Error message
String cannot be deserialized as JSON to a Spectator Histogram
What it means
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.
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.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at extensions-contrib/spectator-histogram/src/main/java/org/apache/druid/spectator/histogram/SpectatorHistogram.java:174 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/7f1129e9703a6780.
Report an issue: GitHub.
Appendix: source
Thrown at extensions-contrib/spectator-histogram/src/main/java/org/apache/druid/spectator/histogram/SpectatorHistogram.java:174
}
if (serializedHistogram instanceof byte[]) {
return fromByteBuffer(ByteBuffer.wrap((byte[]) serializedHistogram));
}
if (serializedHistogram instanceof SpectatorHistogram) {
return (SpectatorHistogram) serializedHistogram;
}
if (serializedHistogram instanceof String) {
// Try parse as JSON into HashMap
try {
HashMap<String, Long> map = JSON_MAPPER.readerFor(HashMap.class).readValue((String) serializedHistogram);
SpectatorHistogram histogram = new SpectatorHistogram();
for (Map.Entry<String, Long> entry : map.entrySet()) {
histogram.add(entry.getKey(), entry.getValue());
}
return histogram;
}
catch (JsonProcessingException e) {
throw new ParseException((String) serializedHistogram, e, "String cannot be deserialized as JSON to a Spectator Histogram");
}
}
if (serializedHistogram instanceof HashMap) {
SpectatorHistogram histogram = new SpectatorHistogram();
for (Map.Entry<?, ?> entry : ((HashMap<?, ?>) serializedHistogram).entrySet()) {
histogram.add(entry.getKey(), (Number) entry.getValue());
}
return histogram;
}
throw new ParseException(
null,
"Object cannot be deserialized to a Spectator Histogram "
+ serializedHistogram.getClass()
);
}
@Nullable
static SpectatorHistogram fromByteBuffer(ByteBuffer buffer)View on GitHub (pinned to 9b90983fd2)