Serializing an arbitrary Java object with Kryo (getting IllegalAccessError)

前端 未结 2 1285
小鲜肉
小鲜肉 2021-01-19 15:47

Motivation:

To aid in remote debugging (Java), it\'s useful to be able to request remote servers to send over arbitrary objects to my local machine for inspection.

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-19 16:25

    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).

提交回复
热议问题