-
Notifications
You must be signed in to change notification settings - Fork 135
Open
Description
You can replace the JSONArray with TypeToken and use GSON to parse the List<Profile> directly.
public class Utils {
@NonNull
public static List<Profile> loadProfiles(Context context) {
BufferedReader reader = null;
try {
AssetManager manager = context.getAssets();
InputStream inputStream = manager.open("profiles.json");
reader = new BufferedReader(new InputStreamReader(inputStream));
Gson gson = new Gson(); // TODO dependency injection
return gson.fromJson(reader, new TypeToken<ArrayList<Profile>>() {}.getType());
} catch(Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
} finally {
if(reader != null) {
try {
reader.close();
} catch(IOException e) {
// Ignore
}
}
}
}
}Metadata
Metadata
Assignees
Labels
No labels