Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

cannot change a non serializable class which has no no-arg constructor  RSS feed

John Maak
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I know that this is quite an old problem and comes up all the time, but I could not really find the solution so far.
So, what can I do if I'd like to re-use a class which is not serializable but does not have a no-arg constructor and I need to make the subclass serializable?

E.g. the class I'd like to reuse and cannot change:
public class Parent {
private final int age;

public Parent(int age) {
this.age = age;
public int getAge() {
return age;
My subclass that I need to make serializable:
public class SerializableChild extends Parent implements Serializable {
private String nickName;

public SerializableChild(int age, String nickName) {
this.nickName = nickName;

public String getNickName() {
return nickName;

Serialization/deserialization does not work because the first non-serializable ancestor (Parent) does not have an available no-arg constructor.

Theoretically creating a SerializableChild instance with the same state should not be such a big problem because I can access all the necessary data (i.e. age and nickName) but because the age can be set only at instantiation I have difficulties with the implementation.

Does anyone know a nice solution to this problem?

The best I can think of is using the Memento Pattern and serialize the memento, but this is not the same.

Thanks for any help,
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!