title: Java Custom Serialization
body: <p>I have an object that contains a few unserializable fields that I want to serialize. They are from a separate API that I cannot change, so making them Serializable is not an option. The main problem is the Location class. It contains four things that can be serialized that I'd need, all ints. How can I use read/writeObject to create a custom serialization method that can do something like this:</p>
  
  <pre><code>// writeObject:
  List&lt;Integer&gt; loc = new ArrayList&lt;Integer&gt;();
  loc.add(location.x);
  loc.add(location.y);
  loc.add(location.z);
  loc.add(location.uid);
  // ... serialization code
  
  // readObject:
  List&lt;Integer&gt; loc = deserialize(); // Replace with real deserialization
  location = new Location(loc.get(0), loc.get(1), loc.get(2), loc.get(3));
  // ... more code
  </code></pre>
  
  <p>How can I do this?</p>