Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 42719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:22:56+00:00 2026-05-10T15:22:56+00:00

I have: class MyClass extends MyClass2 implements Serializable { //… } In MyClass2 is

  • 0

I have:

class MyClass extends MyClass2 implements Serializable {   //... } 

In MyClass2 is a property that is not serializable. How can I serialize (and de-serialize) this object?

Correction: MyClass2 is, of course, not an interface but a class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T15:22:56+00:00Added an answer on May 10, 2026 at 3:22 pm

    As someone else noted, chapter 11 of Josh Bloch’s Effective Java is an indispensible resource on Java Serialization.

    A couple points from that chapter pertinent to your question:

    • assuming you want to serialize the state of the non-serializable field in MyClass2, that field must be accessible to MyClass, either directly or through getters and setters. MyClass will have to implement custom serialization by providing readObject and writeObject methods.
    • the non-serializable field’s Class must have an API to allow getting it’s state (for writing to the object stream) and then instantiating a new instance with that state (when later reading from the object stream.)
    • per Item 74 of Effective Java, MyClass2 must have a no-arg constructor accessible to MyClass, otherwise it is impossible for MyClass to extend MyClass2 and implement Serializable.

    I’ve written a quick example below illustrating this.

     class MyClass extends MyClass2 implements Serializable{    public MyClass(int quantity) {     setNonSerializableProperty(new NonSerializableClass(quantity));   }    private void writeObject(java.io.ObjectOutputStream out)   throws IOException{     // note, here we don't need out.defaultWriteObject(); because     // MyClass has no other state to serialize     out.writeInt(super.getNonSerializableProperty().getQuantity());   }    private void readObject(java.io.ObjectInputStream in)   throws IOException {     // note, here we don't need in.defaultReadObject();     // because MyClass has no other state to deserialize     super.setNonSerializableProperty(new NonSerializableClass(in.readInt()));   } }  /* this class must have no-arg constructor accessible to MyClass */ class MyClass2 {    /* this property must be gettable/settable by MyClass.  It cannot be final, therefore. */   private NonSerializableClass nonSerializableProperty;    public void setNonSerializableProperty(NonSerializableClass nonSerializableProperty) {     this.nonSerializableProperty = nonSerializableProperty;   }    public NonSerializableClass getNonSerializableProperty() {     return nonSerializableProperty;   } }  class NonSerializableClass{    private final int quantity;    public NonSerializableClass(int quantity){     this.quantity = quantity;   }    public int getQuantity() {     return quantity;   } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 61k
  • Answers 61k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Ayende has an implementation for this. http://ayende.com/Blog/archive/2006/12/07/ComplexSearchingQueryingWithNHibernate.aspx May 11, 2026 at 9:41 am
  • added an answer Set SelectionColor before you append, something like: int line =… May 11, 2026 at 9:41 am
  • added an answer Does Data: always appear at the begining of a line?… May 11, 2026 at 9:41 am

Related Questions

I have: class MyClass extends MyClass2 implements Serializable { //... } In MyClass2 is
I have a class: class MyClass: def __init__(self, foo): if foo != 1: raise
I have a class like this: public class myClass { public List<myOtherClass> anewlist =
Suppose I have a class public class MyClass { private Set<String> set = new
I have a class that subclasses NSMutableArray. I init it using: MyClass class =
I have the following structure public class MyClass : MyBaseClass<System.Int32> { } In a
I have a generic class public MyClass<TContext, T> where TContext : DataContext that effectively
I have got a template class as follows: class MyClass<T> { T field; public
If I have a class org.foobar.MyClass and want to put it in a JAR
I have a templated class defined (in part) as template <class T> MyClass {

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.