Skip to content

Commit 449e646

Browse files
committed
Fix the runtime crash of getting Object List
1 parent 3da0fc1 commit 449e646

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

.idea/caches/build_file_checksums.ser

0 Bytes
Binary file not shown.

fastsave/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@ android {
2323
dependencies {
2424
//Gson
2525
implementation 'com.google.code.gson:gson:2.8.2'
26-
implementation 'com.google.guava:guava:24.1-jre'
2726
}

fastsave/src/main/java/com/appizona/yehiahd/fastsave/FastSave.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import android.preference.PreferenceManager;
66
import android.util.Log;
77

8-
import com.google.common.reflect.TypeParameter;
98
import com.google.gson.Gson;
9+
import com.google.gson.reflect.TypeToken;
1010

11+
import java.util.ArrayList;
1112
import java.util.List;
1213
import java.util.Map;
1314

@@ -132,11 +133,18 @@ public <T> List<T> getObjectsList(String key, Class<T> classType) {
132133
if (isKeyExists(key)) {
133134
String objectString = mSharedPreferences.getString(key, null);
134135
if (objectString != null) {
135-
return new Gson().fromJson(objectString, new com.google.common.reflect.TypeToken<List<T>>() {
136+
137+
ArrayList<T> t = new Gson().fromJson(objectString, new TypeToken<List<T>>() {
138+
}.getType());
139+
140+
List<T> finalList = new ArrayList<>();
141+
142+
for (int i = 0; i < t.size(); i++) {
143+
String s = String.valueOf(t.get(i));
144+
finalList.add(new Gson().fromJson(s, classType));
136145
}
137-
.where(new TypeParameter<T>() {
138-
}, classType)
139-
.getType());
146+
147+
return finalList;
140148
}
141149
}
142150

0 commit comments

Comments
 (0)