Partially deserializing a complex Java object

I have a java class hierarchy as follows.

public class Results{
    private String _query;
    private CachedRowSetImpl _resultSet;
    //... getter setters
}

      

I am serializing List<Results> resultList

, consider this list containing 100 elements and each _resultSet has over 1000 records. I have 2 questions,

  • When we deserialize this object, my application memory will contain the entire object and will it create a heap size issue?
  • If this creates a resource problem when I deserialize, can I ignore _resultSet

    as deserialized meaning, a simple query is enough?

Correct me if my understanding is wrong.

+3


source to share


2 answers


If you implement Externalizable

yours readExternal

would look something like this:



     public void readExternal(ObjectInput in) throws IOException,  
         ClassNotFoundException {  
             _query=(String) in.readObject();  
            if(//yourCondition){
             _resultSet=(CachedRowSetImpl) in.readObject();  
            }
         }

      

+1


source


You must implement Serializable. The transient modifier can be used to ignore fields during serialization. I don't know what the CachedRowSetImpl contains, but when you ignore that, then only 100 String objects are unlikely to cause a heap problem.



public class Results implements Serializable{
    private String _query;
    private transient CachedRowSetImpl _resultSet;
    //... getter setters
}

      

0


source







All Articles