UUID在Jackson Avro版本2.11.0以上的字符串序列化

huangapple go评论78阅读模式
英文:

Serialization of UUID to string in Jackson Avro > 2.11.0

问题

我有一个具有UUID属性的对象,我想将其序列化为Avro模式中的字符串。Jackson 2.11引入了修复,以更有效地序列化UUIDs,自那以后我一直在收到以下错误:

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)

有没有办法切换回以前的行为?我们不想改变Avro模式,只是为了升级Jackson。

英文:

I have object with UUID property and I want to serialize it to String in Avro schema. Jackson 2.11 introduced fix to serialize UUIDs more effectively and since then I am getting

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)

Is there any way to switch to previous behavior? We do not want to change Avro schema just to be able to upgrade Jackson.

答案1

得分: 0

这实际上是一个在这里修复的错误:https://github.com/FasterXML/jackson-databind/issues/2815

英文:

It is actually a bug fixed here https://github.com/FasterXML/jackson-databind/issues/2815

huangapple
  • 本文由 发表于 2020年8月6日 17:15:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/63280464.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定