1

Can we serialize/deserialize a Singleton class or class with no default or no parameter constructor in java?

if not what is the way to do it?? will creating a no parameter protected constructor help?

user207421
  • 305,947
  • 44
  • 307
  • 483
Jyotirup
  • 2,882
  • 9
  • 30
  • 38
  • http://stackoverflow.com/a/71399/829571 – assylias Jul 13 '12 at 12:28
  • Yes you can. It isn't the `Serializable` class that needs a no-args constructor, it is its nearest non-`Serializable` base class. See the Object Serialization Specification. – user207421 Aug 16 '23 at 23:51

2 Answers2

0

You can not Serializing/Deserializing Classes only instances of classes

Mark Bakker
  • 1,278
  • 8
  • 19
0

You should create a proxy object for your Singleton and serialize it in the Singleton's stead.

You can read more about proxy serialization here.

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Alexander Pogrebnyak
  • 44,836
  • 10
  • 105
  • 121