Gson字段解析失败兼容(gson-plugin)
一行代码解决Android某个字段gson解析失败,导致网络请求整体失败的问题。
原文
项目github地址
1.工程根目录加入repositories
buildscript { repositories { maven { url 'https://jitpack.io' } } } allprojects { repositories { maven { url 'https://jitpack.io' } } }
2.工程根目录build.gradle加入ClassPath
dependencies { classpath 'com.github.LianjiaTech:gson-plugin:2.0.1' }
3.工程app目录build.gradle加入依赖
apply plugin: 'com.ke.gson.plugin'
4.可选调用(监听异常json字段,建议收到后上报给服务器)
ReaderTools.setListener(new ReaderTools.JsonSyntaxErrorListener() { @Override public void onJsonSyntaxError(String exception, String invokeStack) { //upload error info to server Log.e("test", "json syntax exception: " + exception); Log.e("test", "json syntax invokeStack: " + invokeStack); } });
5.添加混淆keep
-keep class com.google.gson.** { *; } -keep class com.ke.gson.** { *; }
相关推荐
SXIAOYI 2020-09-16
xiaonuoyal 2020-06-17
SXIAOYI 2020-06-11
yinbaoshiguang 2020-06-09
Chydar 2020-06-02
nalanrumeng 2020-06-01
xiaonuoyal 2020-06-01
nalanrumeng 2020-05-19
ITprivate 2020-04-15
xiaonuoyal 2020-04-14
ITprivate 2020-03-26
ITprivate 2020-02-12
nalanrumeng 2020-01-13
xiaonuoyal 2019-12-07
xiaonuoyal 2019-11-18
TOmyhonour 2019-11-16