title: Serializing android.location.Location with Gson
body: <p>In my Android app, I would like to store some locations. I retrieve these locations with Android´s provider and get instances of <a href="http://developer.android.com/reference/android/location/Location.html" rel="nofollow">android.location.Location</a>.</p>
  
  <p>To store data, I serialize my objects to JSON using <a href="https://sites.google.com/site/gson/gson-user-guide" rel="nofollow">Gson</a>. However, I run into some Exception when I manipulate the retrieved Location objects. Here is the stacktrace I get:</p>
  
  <pre><code>java.lang.IllegalArgumentException
          at android.os.Parcel.nativeAppendFrom(Native Method)
          at android.os.Parcel.appendFrom(Parcel.java:431)
          at android.os.Bundle.writeToParcel(Bundle.java:1679)
          at android.os.Parcel.writeBundle(Parcel.java:636)
          at android.location.Location.writeToParcel(Location.java:908)
          at android.os.Parcel.writeTypedList(Parcel.java:1048)
          at com.example.app.bean.PostExtraData.writeToParcel(PostExtraData.java:58)
          at android.os.Parcel.writeParcelable(Parcel.java:1285)
          at com.example.app.bean.Post.writeToParcel(Post.java:166)
          at android.os.Parcel.writeParcelable(Parcel.java:1285)
          at android.os.Parcel.writeValue(Parcel.java:1204)
          at android.os.Parcel.writeArrayMapInternal(Parcel.java:618)
          at android.os.Bundle.writeToParcel(Bundle.java:1692)
          at android.os.Parcel.writeBundle(Parcel.java:636)
  </code></pre>
  
  <p>As we can see, it happens when serializing the Parcelable Location to communicate between Activities. It happens only for Location objects deserialized from JSON. The code causing this in PostExtraData is :</p>
  
  <pre><code>private ArrayList&lt;Location&gt; locations;
  
  @Override
  public void writeToParcel(Parcel parcel, int i) {
    parcel.writeTypedList(locations);
  }
  </code></pre>
  
  <p>Apparently there is something wrong with Location. And actually, I could get to see a representation of the Location instance once it is deserialized from JSON:</p>
  
  <pre><code>Location[fused 65.966700,-18.533300 acc=1 et=+23m6s700ms alt=15.044444 vel=0.0 bear=0.0 {Bundle[mParcelledData.dataSize=-1196422336]}]
  </code></pre>
  
  <p>My question is, what are my options to serialize properly my Location instances? Is my only option to write a specific deserializer for android.location.Location?</p>