当前位置:网站首页>@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
边栏推荐
- Hard core, have you ever seen robots play "escape from the secret room"? (code attached)
- Constrained layout flow
- Six simple cases of QT
- Swift uses userdefaults and codable to save an array of class objects or structure instances
- @SerializedName注解使用
- oracle和mysql批量Merge对比
- To bring Euler's innovation to the world, SUSE should be the guide
- Kotlin Compose 与原生 嵌套使用
- 【系统设计】指标监控和告警系统
- > Could not create task ‘:app:MyTest.main()‘. > SourceSet with name ‘main‘ not found.问题修复
猜你喜欢
Energy momentum: how to achieve carbon neutralization in the power industry?
The king of pirated Dall · e? 50000 images per day, crowded hugging face server, and openai ordered to change its name
90%的人都不懂的泛型,泛型的缺陷和应用场景
Cerebral cortex: directed brain connection recognition widespread functional network abnormalities in Parkinson's disease
[C language] the use of dynamic memory development "malloc"
Fluent generates icon prompt logo widget
宝塔面板MySQL无法启动
[tips] get the x-axis and y-axis values of cdfplot function in MATLAB
Uni app running to wechat development tool cannot Preview
双容水箱液位模糊PID控制系统设计与仿真(Matlab/Simulink)
随机推荐
Design and Simulation of fuzzy PID control system for liquid level of double tank (matlab/simulink)
Swift uses userdefaults and codable to save an array of class objects or structure instances
Matrix processing practice
[论文阅读] KGAT: Knowledge Graph Attention Network for Recommendation
《微信小程序-基础篇》小程序中的事件与冒泡
CSDN always jumps to other positions when editing articles_ CSDN sends articles without moving the mouse
程序员搞开源,读什么书最合适?
Dedecms website building tutorial
Wechat applet - simple diet recommendation (2)
H. 265 introduction to coding principles
How to get the STW (pause) time of GC (garbage collector)?
【系统设计】指标监控和告警系统
让AI替企业做复杂决策真的靠谱吗?参与直播,斯坦福博士来分享他的选择|量子位·视点...
ThreadLocal source code learning
高级 OpenCV:BGR 像素强度图
面试:Bitmap像素内存分配在堆内存还是在native中
QT timer realizes dynamic display of pictures
Click the picture in the mobile browser and the picture will not pop up
(1) Complete the new construction of station in Niagara vykon N4 supervisor 4.8 software
Glide advanced level