quarkusio/quarkus · error · RuntimeException
Cannot deserialize data for data-content-encoding: '${dataCo
Error message
Cannot deserialize data for data-content-encoding: '${dataContentEncoding}'. What it means
JsonCloudEventImpl.data() deserializes the event's JSON payload. If the JSON contains a 'datacontentencoding' attribute with any value other than 'base64', it cannot handle it and throws a RuntimeException naming the encoding.
Source
Thrown at extensions/funqy/funqy-knative-events/runtime/src/main/java/io/quarkus/funqy/runtime/bindings/knative/events/JsonCloudEventImpl.java:191
@Override
public T data() {
if (data != null) {
return data;
}
if ((dataContentType() == null || dataContentType().startsWith("application/json")) && !byte[].class.equals(dataType)) {
data = reader.readValue(event.get("data"));
return data;
} else if (byte[].class.equals(dataType)) {
try {
if (majorSpecVersion() == 0) {
boolean isBase64 = false;
if (event.has("datacontentencoding")) {
String dce = event.get("datacontentencoding").asText();
if ("base64".equals(dce)) {
isBase64 = true;
} else {
throw new RuntimeException("Cannot deserialize data for data-content-encoding: '" + dce + "'.");
}
}
if (isBase64) {
if (event.has("data")) {
String txt = event.get("data").asText();
data = (T) Base64.getDecoder().decode(txt);
return data;
} else {
return null;
}
} else {
if (event.has("data")) {
data = (T) mapper.writeValueAsBytes(event.get("data"));
return data;
} else {
return null;
}
}View on GitHub (pinned to e1c734241f)
Solutions
- Re-publish the event without the datacontentencoding attribute or with 'base64'.
- Preprocess the event JSON to remove/normalize the datacontentencoding field before it reaches the binding.
- Handle the RuntimeException and fall back to manual decoding of the data field.
- Upgrade the event source to CloudEvents 1.0, where datacontentencoding was removed.
Example fix
// before
{"specversion":"1.0","datacontentencoding":"binary","data":"..."}
// after
{"specversion":"1.0","data":"..."} Defensive patterns
Strategy: validation
Validate before calling
JsonNode dce = event.get("datacontentencoding");
if (dce != null && !"base64".equals(dce.asText())) {
throw new IllegalArgumentException("Unsupported datacontentencoding: " + dce.asText());
} Type guard
boolean isSupportedEncoding(JsonNode event) { JsonNode n = event.get("datacontentencoding"); return n == null || "base64".equals(n.asText()); } Try / catch
try { data = event.data(dataType); } catch (RuntimeException e) { if (e.getMessage().contains("data-content-encoding")) { data = manualDecode(event.get("data").asText()); } else throw e; } Prevention
- Publish events without datacontentencoding (removed in CloudEvents 1.0)
- Normalize incoming event JSON to strip legacy encoding fields
- Handle base64 only, decode manually otherwise
- Update legacy event sources (e.g. old SendGrid webhooks) to spec 1.0
When it happens
Trigger: Parsing a JSON-serialized CloudEvent whose datacontentencoding is e.g. 'binary', 'utf-8', or any non-base64 string; the code only special-cases 'base64' and throws otherwise.
Common situations: Event producers (older SendGrid, custom brokers) set datacontentencoding to values from the 0.1 spec era that modern CloudEvents dropped; hand-crafted event JSON with unexpected fields.
Related errors
- Don't know how to get event data (dataContentType: '%s', jav
- Don't know how to get event data (dataContentType: '%s', jav
- Only supported major versions are 0 and 1.
- Function for trigger '${trigger}' has multiple matching invo
- When using CloudEvent<> generic parameter must be used.
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/d73d14d44781af2b.
Report an issue: GitHub.