1

Every example I have seen regarding object serialization, includes an all field constructor and a getter and setter method for every field. Is this nessecary? What do you have to do to make a java object serializable, other tagging it with the serializable interface and assuring all non-transient field are them selves serializable.

2 Answers 2

4

There is nothing required to make an Object serializable, apart from the basic steps you've mentioned. There are no requirements for the existence of getters/setters or constructors of a certain form (though there may be other legitimate reasons to want those).

Sign up to request clarification or add additional context in comments.

1 Comment

Think of getters as a secure way to obtain needed information from your Objects, and setters a good idea in case you need to modify any of it (for whatever reason).
2

The constructor/getters/setters are not mandatory. Non-transient collections although serializable containing references to non-serializable objects will cause failures.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.