CompatibleFieldSerializer does not work

38 views
Skip to first unread message

Guofeng Zhang

unread,
Jul 14, 2016, 11:59:25 PM7/14/16
to kryo-users
Hi,

I tried to use CompatibleFieldSerializer, but it failed, I cannot figure out how to solve it.

For the following test, if I use
   kryo.writeObject(output, outerObject);
I got  
Exception in thread "main" com.esotericsoftware.kryo.KryoException: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.Class
Serialization trace:
clazz (app.SomeClass)
someObject (app.OuterClass)
at com.esotericsoftware.kryo.serializers.ObjectField.write(ObjectField.java:101)
at com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer.write(CompatibleFieldSerializer.java:62)
at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:552)
at com.esotericsoftware.kryo.serializers.ObjectField.write(ObjectField.java:80)
at com.esotericsoftware.kryo.serializers.FieldSerializer.write(FieldSerializer.java:518)
at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:534)
at app.KyroTest.outputTest(KyroTest.java:42)
at app.KyroTest.main(KyroTest.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.Class
at com.esotericsoftware.kryo.serializers.DefaultSerializers$ClassSerializer.write(DefaultSerializers.java:314)
at com.esotericsoftware.kryo.Kryo.writeObjectOrNull(Kryo.java:606)
at com.esotericsoftware.kryo.serializers.ObjectField.write(ObjectField.java:87)
... 12 more

If I use
   kryo.writeObject(output, someObject);
I got    
Exception in thread "main" com.esotericsoftware.kryo.KryoException: java.lang.NullPointerException
Serialization trace:
annotations (app.SomeClass$SKU)
skus (app.SomeClass)
at com.esotericsoftware.kryo.serializers.ObjectField.write(ObjectField.java:101)
at com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer.write(CompatibleFieldSerializer.java:62)
at com.esotericsoftware.kryo.Kryo.writeObjectOrNull(Kryo.java:606)
at com.esotericsoftware.kryo.serializers.CollectionSerializer.write(CollectionSerializer.java:93)
at com.esotericsoftware.kryo.serializers.CollectionSerializer.write(CollectionSerializer.java:40)
at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:552)
at com.esotericsoftware.kryo.serializers.ObjectField.write(ObjectField.java:80)
at com.esotericsoftware.kryo.serializers.FieldSerializer.write(FieldSerializer.java:518)
at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:534)
at app.KyroTest.outputTest(KyroTest.java:43)
at app.KyroTest.main(KyroTest.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.NullPointerException
at com.esotericsoftware.kryo.Kryo.writeReferenceOrNull(Kryo.java:642)
at com.esotericsoftware.kryo.Kryo.writeObjectOrNull(Kryo.java:593)
at com.esotericsoftware.kryo.serializers.ObjectField.write(ObjectField.java:87)
... 15 more

The attached is the source.

Thanks for your help very much.

Guofeng


app.zip
Reply all
Reply to author
Forward
0 new messages