在 Jackson Avro > 2.11.0 中将 UUID 序列化为字符串

Serialization of UUID to string in Jackson Avro > 2.11.0

我有 UUID 属性 的对象,我想将它序列化为 Avro 模式中的字符串。 Jackson 2.11 引入了 fix 以更有效地序列化 UUID,从那时起我得到

Caused by: java.lang.ClassCastException: class [B cannot be cast to class java.lang.CharSequence ([B and java.lang.CharSequence are in module java.base of loader 'bootstrap')
    at org.apache.avro.generic.GenericDatumWriter.writeString(GenericDatumWriter.java:323)
    at org.apache.avro.generic.GenericDatumWriter.writeString(GenericDatumWriter.java:315)
    at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:150)
    at com.fasterxml.jackson.dataformat.avro.ser.NonBSGenericDatumWriter.write(NonBSGenericDatumWriter.java:123)
    at org.apache.avro.generic.GenericDatumWriter.writeField(GenericDatumWriter.java:206)
    at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:195)
    at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:130)
    at com.fasterxml.jackson.dataformat.avro.ser.NonBSGenericDatumWriter.write(NonBSGenericDatumWriter.java:123)
    at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:72)
    at com.fasterxml.jackson.dataformat.avro.ser.RootContext.complete(RootContext.java:122)
    at com.fasterxml.jackson.dataformat.avro.AvroGenerator._complete(AvroGenerator.java:621)
    at com.fasterxml.jackson.dataformat.avro.AvroGenerator.writeEndObject(AvroGenerator.java:410)
    at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:180)
    at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)

有什么方法可以切换到以前的行为吗?我们不想为了升级 Jackson 而更改 Avro 架构。

这里其实是修复了一个bughttps://github.com/FasterXML/jackson-databind/issues/2815