If the library does not support certain Avro types (like specific logical types), you can implement the AvroTypeConverter interface to define custom conversion logic. You can target specific fields by checking the path in the canManage method.
To apply your custom converter, instantiate JsonAvroConverter using a CompositeJsonToAvroReader containing your custom converter.
public class CustomFieldConverter implements AvroTypeConverter {
@Override
public Object convert(Schema.Field field, Schema schema, Object jsonValue, Deque<String> path, boolean silently) {
return "custom-" + jsonValue;
}
@Override
public boolean canManage(Schema schema, Deque<String> path) {
return "customField".equals(path.getLast());
}
}
// Usage:
JsonAvroConverter converter = new JsonAvroConverter(new CompositeJsonToAvroReader(new CustomFieldConverter()));