当前位置:网站首页>@JsonAdapter注解使用
@JsonAdapter注解使用
2022-07-05 09:41:00 【沙漠一只雕得儿得儿】
接管序列化和反序列化过程
TypeAdapter接管了序列化和反序列化过程,而JsonSerializer和JsonDeserializer则只分别单独接管序列化和反序列化过程。
作用在POJO类上的,接收一个参数,且必须是TypeAdpater,JsonSerializer或JsonDeserializer这三个其中之一。
前面的JsonSerializer和JsonDeserializer都要配合GsonBuilder.registerTypeAdapter使用,但每次使用都要注册也太麻烦了,JsonAdapter就是为了解决这个痛点的。
使用:
@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("我",10);
Log.i("adapter","user:"+new Gson().toJson(user));//直接使用简单的new GSON()即可,无需配置注册边栏推荐
- 90%的人都不懂的泛型,泛型的缺陷和应用场景
- Cut off 20% of Imagenet data volume, and the performance of the model will not decline! Meta Stanford et al. Proposed a new method, using knowledge distillation to slim down the data set
- [technical live broadcast] how to rewrite tdengine code from 0 to 1 with vscode
- 【 conseils 】 obtenir les valeurs des axes X et y de la fonction cdfplot dans MATLAB
- 【C语言】动态内存开辟的使用『malloc』
- 美图炒币半年亏了3个亿,华为被曝在俄罗斯扩招,AlphaGo的同类又刷爆一种棋,今日更多大新闻在此...
- From "chemist" to developer, from Oracle to tdengine, two important choices in my life
- Wechat applet - simple diet recommendation (4)
- Idea debugs com intellij. rt.debugger. agent. Captureagent, which makes debugging impossible
- Implementation of smart home project
猜你喜欢

Tdengine connector goes online Google Data Studio app store

TDengine 连接器上线 Google Data Studio 应用商店

程序员如何活成自己喜欢的模样?
![[tips] get the x-axis and y-axis values of cdfplot function in MATLAB](/img/08/2d039df6ea3ace8685512b2af8281d.png)
[tips] get the x-axis and y-axis values of cdfplot function in MATLAB

从“化学家”到开发者,从甲骨文到 TDengine,我人生的两次重要抉择

Charm of code language

On July 2, I invite you to TD Hero online press conference

Node red series (29): use slider and chart nodes to realize double broken line time series diagram

Officially launched! Tdengine plug-in enters the official website of grafana

Idea debugs com intellij. rt.debugger. agent. Captureagent, which makes debugging impossible
随机推荐
Android SQLite database encryption
ArcGIS Pro 创建要素
Tdengine connector goes online Google Data Studio app store
Unity particle special effects series - the poison spray preform is ready, and the unitypackage package is directly used - on
搞数据库是不是越老越吃香?
Swift saves an array of class objects with userdefaults and nssecurecoding
Develop and implement movie recommendation applet based on wechat cloud
cent7安装Oracle数据库报错
Data visualization platform based on template configuration
Jupiter notebook shortcut key
MySQL字符类型学习笔记
QT event filter simple case
双容水箱液位模糊PID控制系统设计与仿真(Matlab/Simulink)
Cerebral cortex: directed brain connection recognition widespread functional network abnormalities in Parkinson's disease
Baidu app's continuous integration practice based on pipeline as code
idea用debug调试出现com.intellij.rt.debugger.agent.CaptureAgent,导致无法进行调试
[tips] get the x-axis and y-axis values of cdfplot function in MATLAB
Design of stepping motor controller based on single chip microcomputer (forward rotation and reverse rotation indicator gear)
C#函数返回多个值方法
宝塔面板MySQL无法启动