sBourne
sBourne

Reputation: 481

When to use GSON to parse object?

I am trying to pass an array list of objects from one activity to another. I have seen people use the GSON library to serialize objects, and have also seen people make their object implement the Parceable interface, or the Serializable interface. I am curious as to what the technical difference/advantages of using one over the other is.

Please note, this is not meant to be an opinion-based question, more of a technical inquiry.

Thanks in advance.

Upvotes: 2

Views: 306

Answers (1)

Samuel
Samuel

Reputation: 17171

Parcelable is the Android-specific recommended way to get data from one activity to another. See How do I pass data between Activities in Android application? for the specifics of how to do the passing.

Now if you were implementing a cross-platform application, or if you needed to send the same model to a web service, it might be beneficial to use JSON as a serialization format. Serializable could be used if you were only cross-platform but always with JVM languages. That said I would just implement both interfaces and use the best method for each application. JSON over the network and Parcels between activities.

In general when choosing a serialization method, you should consider what qualities you're looking for. Qualities like:

  • Maintainability
  • Network size
  • Serialization/Deserialization performance
  • Ease of implementation
  • Human readability

Pick whichever serialization format will get you the best for your use cases, and implement as many as you need to cover all of your use cases.

Upvotes: 3

Related Questions