Gson
来源:互联网 发布:计算机中文编程 编辑:程序博客网 时间:2024/06/03 22:41
Serialize Object
- GetAdapter from basic adapter factories
- Not found basic adapter, ReflectiveTypeAdapterFactory will create this object type adapter, RefectiveTypeAdapterFactory::Adapter
- Recursive object create boundfields, every filed is basic type with basic adapter
- RefectiveTypeAdapterFactory::Adapter write will call every boundfield's adapter to write.
Deserialize Object
- Get Adapter just likes Serialize Object
- Contructor instance
- Set value to instance
Serialize Collecion<Object>
- GetAdapter from basic adapter: get collectionAdapter
- When write every element with objectAdapter
- ObjectAdapter will check the value type then get sub type adapter or collection adapter. it will check element run time type, then find the reasonable adatper
Deserialize Collection<Object>
- GetAdapter from basic adapter: get collectionAdapter
- When read every element, it constructor Map to read element value, as it can't get element type. Just assign value to Collection<Object> with Collection<Map<String, Object>>
- But it will throw exception when you get the element with Object type, as it can't convert Map to Object
- For solve this problem, Gson define class TypeToken to get element type, in typeToken, it returns ParameterizedType it will includes collection type and element type , collection adapter will include element type adatper
RefectiveTypeAdapterFactory::Adapterhas boundFields, every boundField connects to a Adapter via closure. ThisAdapter may be Collection adapter or RefectiveTypeAdapterFactory::Adapter orsome basic adapter in builtin factories
Summary:
Serialize object: gson willfind adapter , then call adapter read. Collection adapter read function willfind element adapter then call element adapter. Imbeded object adapter will been fetched recursively at the firsttime .
Derialize object: gson will find adatper, then constructer object ,then call adapter write. The process is the same as serialize object.
0 0
- Gson
- Gson
- Gson
- Gson
- GSON
- Gson
- Gson
- Gson
- Gson
- gson
- GSON
- Gson
- Gson
- Gson
- GSON
- gson
- gson
- Gson
- 未来智能手机摄像技术发展趋势:应用
- 决策树算法
- 浅谈CSRF攻击方式
- 附录:球钟代码
- nyoj 21 三个水杯
- Gson
- 常用设计没模式
- spark RDD算子(三) distinct,union,intersection,subtract,cartesian
- Single Element in a Sorted Array
- Tire树模板
- 马来西亚之旅——吉隆坡、马六甲、槟城和亚庇攻略
- 常用自适应样式 CSS 布局
- VS2013调用caffe新建自己的工程详细过程
- 线性结构之串