1

I have a few classes linked to each other

public class A implements java.io.Serializable{
    public B objB;
}

public class B {//doesn't implement serializable
}

When I try to serialize A, I get error because B is not serializable What I want to do is to serialize A and load B again after de-serializing

1 Answer 1

6

use transient for ignore objB during serialization:

The easiest technique is to mark fields that contain sensitive data as private transient. Transient fields are not persistent and will not be saved by any persistence mechanism.

public class A implements java.io.Serializable {
    public transient B objB;
}
Sign up to request clarification or add additional context in comments.

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.