title: Completing object construction after GSON deserialization
body: <p>I have successfully started using GSON to serialize and de-serialize a hierarchy of objects in my Android application. </p>
  
  <p>Some of the objects being serialized have members which I must mark as <code>transient</code> (or otherwise use alternative GSON annotations to prevent them being serialized) because they are references to objects that I do not want to serialize as part of the output JSON string. Those references are to objects which must be separately constructed by some other means. </p>
  
  <p>Once the structure is de-serialized back into Java objects, at some point I need to fill in those references. I could easily do this perhaps by using a series of <code>setXXX()</code> type methods, but until that is done, those objects are in an incomplete state. What I am therefore wondering is whether there is a more robust approach to this. </p>
  
  <p>Ways I have thought of so far:</p>
  
  <ol>
  <li><p>Have the objects throw a <code>RuntimeException</code> (or something more suitable) if they're in an incomplete state; that is, if they're asked to do some work when some initialization method wasn't called. </p></li>
  <li><p>Separate out the serializable bits into a separate data model object. In other words, take out the stuff that can't be serialized. After GSON de-serialization, build up my 'real' objects using those data objects in their composition. This seems to defeat the convenience of using GSON somewhat. </p></li>
  <li><p>Write a custom deserializer for GSON to handle the special creation of those objects. </p></li>
  </ol>