FastJson及Gson定义字段别名

如果开发设计Model的字段名和网络传输Json的字段名不一致,可能导致Json框架(如FastJson和Gson)不能成功解析,此时需要利用FastJson和Gson定义字段别名,实现Model字段和Json字段的匹配。

FastJson

@JSONField("username")
private String userName;

@JSONField(name = "username")
private String userName;

@JSONField(alternateNames = {"username", "user_name"})
private String userName;

Gson

@SerializedName("username")
private String userName;

@SerializedName(value = "username")
private String userName;

@SerializedName(value = "userName", alternate = {"username", "user_name"})
private String userName;
上一篇 使用easyexcel读写Excel
下一篇 Maven编译dubbo.xsd问题解决办法
目录
文章列表
1 HTML5触摸事件(touchstart、touchmove和touchend)
HTML5触摸事件(touchstart、touchmove和touchend)
2
ZooKeeper实现分布式锁
ZooKeeper实现分布式锁
3
Android 加载GIF图最佳实践方案
Android 加载GIF图最佳实践方案
4
Spring Boot使用ApplicationEvent和Listener快速实现业务解耦
Spring Boot使用ApplicationEvent和Listener快速实现业务解耦
5
Android在代码中如何获取应用签名及sha1值
Android在代码中如何获取应用签名及sha1值
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。