当前位置:网站首页>@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
边栏推荐
- Application of data modeling based on wide table
- View Slide
- Common fault analysis and Countermeasures of using MySQL in go language
- Is it really reliable for AI to make complex decisions for enterprises? Participate in the live broadcast, Dr. Stanford to share his choice | qubit · viewpoint
- Tianlong Babu TLBB series - about items dropped from packages
- Implementation of smart home project
- @SerializedName注解使用
- ArcGIS Pro creating features
- 横向滚动的RecycleView一屏显示五个半,低于五个平均分布
- Single chip microcomputer principle and Interface Technology (esp8266/esp32) machine human draft
猜你喜欢
How Windows bat script automatically executes sqlcipher command
【C语言】动态内存开辟的使用『malloc』
程序员如何活成自己喜欢的模样?
基于单片机步进电机控制器设计(正转反转指示灯挡位)
mongoDB副本集
H. 265 introduction to coding principles
To bring Euler's innovation to the world, SUSE should be the guide
mysql80服务不启动
Wechat applet - simple diet recommendation (3)
[tips] get the x-axis and y-axis values of cdfplot function in MATLAB
随机推荐
Coordinate system of view
Apache dolphin scheduler system architecture design
MySQL字符类型学习笔记
mongoDB副本集
Comparison of batch merge between Oracle and MySQL
NCP1342芯片替代料PN8213 65W氮化镓充电器方案
Optimize database queries using the cursor object of SQLite
Design of stepping motor controller based on single chip microcomputer (forward rotation and reverse rotation indicator gear)
Roll up, break 35 - year - old Anxiety, animation Demonstration CPU recording Function call Process
横向滚动的RecycleView一屏显示五个半,低于五个平均分布
QT timer realizes dynamic display of pictures
StaticLayout的使用详解
View Slide
> Could not create task ‘:app:MyTest.main()‘. > SourceSet with name ‘main‘ not found.问题修复
《剑来》语句摘录(七)
如何判断线程池已经执行完所有任务了?
一个程序员的职业生涯到底该怎么规划?
Applet image height adaptation and setting text line height
@JsonAdapter注解使用
《微信小程序-基础篇》小程序中的事件与冒泡