Skip to content

Commit

Permalink
bugfix:
Browse files Browse the repository at this point in the history
处理高版本Gson对原调用逻辑的异常
  • Loading branch information
GitHubWebb committed Jan 5, 2024
1 parent fbe5ff6 commit 79b10b5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion frameLibraryWidget/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ dependencies {
api 'com.squareup.okhttp3:okhttp:3.9.1'

/*Network*/
compileOnly 'com.google.code.gson:gson:2.10.1'
api 'com.google.code.gson:gson:2.10.1'

api('com.squareup.retrofit2:retrofit:2.3.0') {
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

/**
* Adapt a homogeneous collection of objects.
* link: [https://www.jianshu.com/p/39d52bc2e49c]
* <p>
* {
* "code":200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public class GsonUtil {
Field f = builder.getDeclaredField("instanceCreators");
f.setAccessible(true);
Map<Type, InstanceCreator<?>> val = (Map<Type, InstanceCreator<?>>) f.get(gsonBuilder);
gsonBuilder.registerTypeAdapterFactory(new CustomCollectionTypeAdapterFactory(new ConstructorConstructor(val)));
gsonBuilder.registerTypeAdapterFactory(new CustomCollectionTypeAdapterFactory(new ConstructorConstructor(val, true, new ArrayList())));
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
gsonBuilder.registerTypeAdapterFactory(new CustomCollectionTypeAdapterFactory(new ConstructorConstructor(new HashMap<Type, InstanceCreator<?>>())));
gsonBuilder.registerTypeAdapterFactory(new CustomCollectionTypeAdapterFactory(new ConstructorConstructor(new HashMap<Type, InstanceCreator<?>>(), true, new ArrayList())));
}

gson = gsonBuilder.create();
Expand Down

0 comments on commit 79b10b5

Please sign in to comment.