-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Closed
Description
public class Filter extends Object implements Serializable{
private static final long serialVersionUID = 4944267946319467028L;
SparseArray<List<Integer>> catalogue = new SparseArray<List<String>>();
....
}
I'm filling catalogue variable with next values : {0=>{1,2,3,4}, 3=>{20,21,22}
...}
Then I'm saving Filter object like this:
...
ArrayList<Filter> filterList;
.....
public void saveFilter(Filter filterModel){
filterList.add(filterModel);
Gson gson = new Gson();
String jsonStr = gson.toJson(filterList);
// For example save as
preference = activity.getSharedPreferences("SJ_MAIN_STORAGE", Context.MODE_PRIVATE);
Editor editor = preference.edit();
editor.putString(key, jsonStr);
editor.commit();
}
I'm getting Filter object this way :
public ArrayList<Filter> getFilter{
Gson gson = new Gson();
ArrayList<Filter> arrayList = new ArrayList<Filter>();
String json = preference.getString(key, "");
if (hStrings.isEmpty(json)) return arrayList;
JsonParser parser = new JsonParser();
JsonArray array = parser.parse(json).getAsJsonArray();
try{
for(int i = 0; i < array.size(); i++)
{
arrayList.add(gson.fromJson(array.get(i), Filter.class));
}
}catch(Exception e){
}
return arrayList ;
}
I have the next result of catalogue value: {0=>{1.0,2.0,3.0,4.0},
3=>{20.0,21.0,22.0} ...}
(integer values of array become a float values).
Is it right behavior?
Thank you.
Original issue reported on code.google.com by [email protected] on 12 Feb 2014 at 3:00
Metadata
Metadata
Assignees
Labels
No labels