Gson parsing a source

Android development is Gson common network data parsing library, used often easy to overlook its wonderful interior, and then I will open a series Gson source resolution, but see a very long article, you need some patience, this series my intention is to fight every article short and sophisticated "piece" to allow readers to quickly read and understand.

Parsing the source code need to find a point cut will not get lost in the mass of code, I find someone to start with the most commonly used functions,

The first is fromJson (String json, Type typeOfT), is to be mapped to a string bean (Type of java in all types of ultra-Interface), fromJson a series of heavy-duty, the last call

fromJson(JsonReader reader, Type typeOfT),

 JsonReader (for the time being is not the table, will be described in detail later), can be understood as json format can be read iterator content so laid down, it creates a TypeToken (for the time being is not the table, will be described in detail later), it can be understood as a self storage key definition, go, call getAdapter get a TypeAdapter, after calling TypeAdapter object of the read function completes bean mapping, TypeAdapter is an abstract type, apparently specific maps will be delayed to subclasses, calling read and write after obtaining specific TypeAdapter function to complete formGson and toGson.

ok, to sum up, it is generally 2

1. Obtain specific TypeAdapter.

2. The implementation of specific TypeAdapter (read or write).

Next would be the first step for resolution.

Guess you like

Origin www.cnblogs.com/xiaoshuailong/p/11093382.html