当前位置:网站首页>@Jsonadapter annotation usage
@Jsonadapter annotation usage
2022-07-05 10:12:00 【A bird carved in the desert】
You really can use Gson Do you ?Gson Use guide ( Four ) - Simple books
You really can use Gson Do you ?Gson Use guide ( One ) - Simple books
Take over serialization and deserialization process
TypeAdapter
Took over the serialization and deserialization process , and JsonSerializer
and JsonDeserializer
Then only take over the serialization and deserialization processes separately .
It works on POJO class Upper , Receive a parameter , And it must be TypeAdpater,JsonSerializer or JsonDeserializer One of these three .
Ahead JsonSerializer
and JsonDeserializer
All have to cooperate with GsonBuilder.registerTypeAdapter
Use , But it's too troublesome to register every time you use it ,JsonAdapter
Is to solve this pain point .
Use :
@JsonAdapter(UserTypeAdapter.class)
public final class User {
.....
}
public class UserTypeAdapter implements JsonSerializer<User> {
@Override
public JsonElement serialize(User src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject jsonElement = new JsonObject();
jsonElement.addProperty("name","serialize");
return jsonElement;
}
}
User user = new User(" I ",10);
Log.i("adapter","user:"+new Gson().toJson(user));// Direct use of simple new GSON() that will do , No configuration registration required
边栏推荐
- 面试:List 如何根据对象的属性去重?
- > Could not create task ‘:app:MyTest.main()‘. > SourceSet with name ‘main‘ not found.问题修复
- Generics, generic defects and application scenarios that 90% of people don't understand
- Tianlong Babu TLBB series - questions about skill cooling and the number of attack ranges
- ConstraintLayout的流式布局Flow
- 横向滚动的RecycleView一屏显示五个半,低于五个平均分布
- 学习笔记6--卫星定位技术(上)
- [论文阅读] KGAT: Knowledge Graph Attention Network for Recommendation
- Cerebral Cortex:有向脑连接识别帕金森病中广泛存在的功能网络异常
- Swift uses userdefaults and codable to save an array of class objects or structure instances
猜你喜欢
QT event filter simple case
Node red series (29): use slider and chart nodes to realize double broken line time series diagram
Apache DolphinScheduler 入门(一篇就够了)
Cerebral cortex: directed brain connection recognition widespread functional network abnormalities in Parkinson's disease
善用兵者,藏于无形,90 分钟深度讲解最佳推广价值作品
uniapp + uniCloud+unipay 实现微信小程序支付功能
Apache dolphin scheduler system architecture design
一种用于干式脑电图的高密度256通道电极帽
Small program startup performance optimization practice
学习笔记4--高精度地图关键技术(下)
随机推荐
MySQL digital type learning notes
Pagoda panel MySQL cannot be started
Fluent generates icon prompt logo widget
[app packaging error] to proceed, either fix the issues identified by lint, or modify your build script as follow
B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条...
钉钉、企微、飞书学会赚钱了吗?
[NTIRE 2022]Residual Local Feature Network for Efficient Super-Resolution
TypeError: Cannot read properties of undefined (reading ‘cancelToken‘)
How to correctly evaluate video image quality
Single chip microcomputer principle and Interface Technology (esp8266/esp32) machine human draft
Dedecms website building tutorial
Cent7 Oracle database installation error
一个程序员的职业生涯到底该怎么规划?
Unity particle special effects series - the poison spray preform is ready, and the unitypackage package is directly used - on
Constrained layout flow
Apache dolphin scheduler system architecture design
面试:List 如何根据对象的属性去重?
(1) Complete the new construction of station in Niagara vykon N4 supervisor 4.8 software
Lepton 无损压缩原理及性能分析
Z-blog template installation and use tutorial