provectus/kafka-ui · error · ValidationException
' ' does not fit schema
Error message
'%s' does not fit schema: %s
What it means
After successfully parsing the value as JSON, serializeJson validates it against the topic's registered JSON Schema. When the document violates the schema (missing required fields, wrong types, failed enum/pattern/minimum constraints), this ValidationException reports all violations via e.getAllMessages().
Solutions
- Read the getAllMessages() list in the error - each entry names the failing path and constraint; fix those fields
- Fetch the latest subject version from Schema Registry and align your payload to it
- Validate locally with the same schema (everit org.everit.json.schema) before producing
- If the schema itself is wrong, register a corrected/new schema version rather than bypassing validation
Example fix
// before (schema requires int id)
String value = "{\"id\": \"42\"}";
// after
String value = "{\"id\": 42}"; Defensive patterns
Strategy: validation
Validate before calling
JsonSchema schema = /* load latest subject version from Schema Registry */; schema.validate(new org.json.JSONObject(value)); // throws before calling kafka-ui if invalid
Try / catch
try {
schema.validate(new org.json.JSONObject(value));
} catch (org.everit.json.schema.ValidationException e) {
e.getAllMessages().forEach(System.err::println); // fix exactly these paths
} Prevention
- Pre-validate locally against the exact schema version fetched from Schema Registry
- Automate compatibility checks when evolving schemas so old payload shapes don't break
- Generate payloads from the schema (e.g. jsonschema2pojo) instead of hand-writing JSON
When it happens
Trigger: Producing a message with the Json serde where the value parses as JSON but violates the schema registered in Schema Registry for the topic - e.g. a required property is missing, a string appears where an integer is expected, or a value is outside its enum.
Common situations: Schema evolved (new required field added) and old payload shapes no longer validate; manually typed message missing fields; numeric ID sent as string; payload built against a different schema version than the one registered for the topic.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- ' ' is not valid json
- seekTo should be set if seekType is
- Serde can't be applied for ' ' topic's serialization
- Something went wrong during adding replicas
- Something went wrong during removing replicas
AI-assisted analysis of provectus/kafka-ui@83b5a60cc0 (2026-09-08).
Data as JSON: /api/errors/44793c234711a9e4.
Report an issue: GitHub.
Appendix: source
Thrown at kafka-ui-api/src/main/java/com/provectus/kafka/ui/serdes/builtin/sr/Serialize.java:52
private static final byte MAGIC = 0x0;
private static final ObjectMapper JSON_SERIALIZE_MAPPER = Jackson.newObjectMapper(); //from confluent package
private Serialize() {
}
@KafkaClientInternalsDependant("AbstractKafkaJsonSchemaSerializer::serializeImpl")
@SneakyThrows
static byte[] serializeJson(JsonSchema schema, int schemaId, String value) {
JsonNode json;
try {
json = JSON_SERIALIZE_MAPPER.readTree(value);
} catch (JsonProcessingException e) {
throw new ValidationException(String.format("'%s' is not valid json", value));
}
try {
schema.validate(json);
} catch (org.everit.json.schema.ValidationException e) {
throw new ValidationException(
String.format("'%s' does not fit schema: %s", value, e.getAllMessages()));
}
try (var out = new ByteArrayOutputStream()) {
out.write(MAGIC);
out.write(schemaId(schemaId));
out.write(JSON_SERIALIZE_MAPPER.writeValueAsBytes(json));
return out.toByteArray();
}
}
@KafkaClientInternalsDependant("AbstractKafkaProtobufSerializer::serializeImpl")
@SneakyThrows
static byte[] serializeProto(SchemaRegistryClient srClient,
String topic,
Serde.Target target,
ProtobufSchema schema,
int schemaId,
String input) {View on GitHub (pinned to 83b5a60cc0)