Serializing an arbitrary Java object with Kryo (getting IllegalAccessError)

不问归期 提交于 2019-12-01 18:28:29

I think, you want kryo.setInstantiatorStrategy(new StdInstantiatorStrategy()); to avoid constructor invocation. More info here.

But, if I may ask, why in the world would you want to serialize a PrintWriter? That is definitely asking for trouble. Kryo is not a "silver bullet", while its default derializers can work with most classes, that are practical (and even then there are always corner cases for which you need to write custom plugins), you can certainly not expect it to be able to handle every single exotic thing you can come up with (and serializing classes backed by internal jvm-specific code, like sun.* definitely qualifies as exotic).

This error is pretty common with Kryo. Problem is that UTF_8 class is not public and hence Kryo fails. Adding below custom serializer helped me to resolve it. It would be a good idea to ship below kind of serializer along with Kryo as lot of people struggles with this.

Custom serializer for kryo for UTF-8 and other charsets

This way you are telling Kryo that for all registered Charset classes, call my custom serializer. Where I am just emitting string name.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!