{"record":{"id":"44793c234711a9e4","repo":"provectus/kafka-ui","slug":"s-does-not-fit-schema-s","errorCode":null,"errorMessage":"'%s' does not fit schema: %s","messagePattern":"'(.+?)' does not fit schema: (.+?)","errorType":"validation","errorClass":"ValidationException","httpStatus":400,"severity":"error","filePath":"kafka-ui-api/src/main/java/com/provectus/kafka/ui/serdes/builtin/sr/Serialize.java","lineNumber":52,"sourceCode":"  private static final byte MAGIC = 0x0;\n  private static final ObjectMapper JSON_SERIALIZE_MAPPER = Jackson.newObjectMapper(); //from confluent package\n\n  private Serialize() {\n  }\n\n  @KafkaClientInternalsDependant(\"AbstractKafkaJsonSchemaSerializer::serializeImpl\")\n  @SneakyThrows\n  static byte[] serializeJson(JsonSchema schema, int schemaId, String value) {\n    JsonNode json;\n    try {\n      json = JSON_SERIALIZE_MAPPER.readTree(value);\n    } catch (JsonProcessingException e) {\n      throw new ValidationException(String.format(\"'%s' is not valid json\", value));\n    }\n    try {\n      schema.validate(json);\n    } catch (org.everit.json.schema.ValidationException e) {\n      throw new ValidationException(\n          String.format(\"'%s' does not fit schema: %s\", value, e.getAllMessages()));\n    }\n    try (var out = new ByteArrayOutputStream()) {\n      out.write(MAGIC);\n      out.write(schemaId(schemaId));\n      out.write(JSON_SERIALIZE_MAPPER.writeValueAsBytes(json));\n      return out.toByteArray();\n    }\n  }\n\n  @KafkaClientInternalsDependant(\"AbstractKafkaProtobufSerializer::serializeImpl\")\n  @SneakyThrows\n  static byte[] serializeProto(SchemaRegistryClient srClient,\n                               String topic,\n                               Serde.Target target,\n                               ProtobufSchema schema,\n                               int schemaId,\n                               String input) {","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/provectus/kafka-ui/blob/83b5a60cc08501b570a0c4d0b4cdfceb1b88d6b7/kafka-ui-api/src/main/java/com/provectus/kafka/ui/serdes/builtin/sr/Serialize.java#L34-L70","documentation":"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().","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (schema requires int id)\nString value = \"{\\\"id\\\": \\\"42\\\"}\";\n// after\nString value = \"{\\\"id\\\": 42}\";","handlingStrategy":"validation","validationCode":"JsonSchema schema = /* load latest subject version from Schema Registry */;\nschema.validate(new org.json.JSONObject(value)); // throws before calling kafka-ui if invalid","typeGuard":null,"tryCatchPattern":"try {\n  schema.validate(new org.json.JSONObject(value));\n} catch (org.everit.json.schema.ValidationException e) {\n  e.getAllMessages().forEach(System.err::println); // fix exactly these paths\n}","preventionTips":["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"],"tags":["kafka","json-schema","serialization","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"83b5a60cc08501b570a0c4d0b4cdfceb1b88d6b7","analyzedAt":"2026-09-08T04:35:39.002Z","contentChangedAt":"2026-09-08T04:35:39.002Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}