79454501

Date: 2025-02-20 12:30:35
Score: 0.5
Natty:
Report link

I found a solution in the SMT

It seams as the AvroConverter is stricter than the JsonSchemaConverter.
In case of null values, the schema provided needs to match the null value and needs to be optional in order to pass the checks in AvroData class.

  public R apply(R record) {
    Struct origStruct = Requirements.requireStruct(record.value(), "flat");

    Schema newSchema;
    Struct targetStruct;

    if (String.valueOf(origStruct.get(this.checkField)).equals(this.checkContent)) {
      targetStruct = null;
      newSchema = SchemaBuilder.struct().optional().build();
    } else {
      targetStruct = origStruct;
      newSchema = targetStruct.schema();
    }

    return record.newRecord(
        record.topic(),
        record.kafkaPartition(),
        record.keySchema(),
        record.key(),
        newSchema,
        targetStruct,
        record.timestamp());
  }

It seems wrong to me as a final solution - but it works for the moment.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: mauam