Chapter 12. Serialization and Transports
To serialize an object we convert the abstract concept (the “model”) to transportable entities, usually either a String
representation of the model, like XML or JSON, or bytes.
To deserialize data means to convert it from a series of entities to an object your program recognizes. For example, you might have an Author
entity with a name
property.
Tasks
In this chapter, you’ll learn to:
-
Serialize and deserialize an object instance.
Android
Android uses a lot of XML internally, but in the real world, JSON is still the primary serialization mechanism (although larger organizations with plenty of engineering resources have started to embrace “protobuf,” or Protocol Buffers). This is a neat concept and highly performant, but beyond the scope of our examination of the framework and standard APIs.
Serialize and Deserialize an Object Instance
In Java and Android, deserialization probably starts with a data model, like this:
Deserialized to JSON, an Author
instance that returned “Mike” by invoking getName
would probably look like this:
{ name : "Mike" }
Once it’s in JSON format, it can be passed along with a network request, written to disk, or even handed off to another program in wildly different technologies; since the JSON format has an established ...
Get Native Mobile Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.