In java how do I serialize a class that is not marked Serializable?

前端 未结 4 1905
醉梦人生
醉梦人生 2020-12-07 01:09

There is a specific class in a third party library that I want to serialize. How would I go about doing this?

I\'m assuming I will have to write a method that tak

4条回答
  •  既然无缘
    2020-12-07 01:40

    A lot depends on the nature of the third party class. Is it final, does it have a no argument constructor, can you construct it given known values or is it constructed by another class, does it itself contain non-Serializable members?

    Easiest way is to decompile the class, add an implements Serializable, and recompile it, but if it contains non-Serializable members, things get more complicated.

提交回复
热议问题