Last active
April 7, 2017 05:09
-
-
Save truongngoclinh/1246d76ec3803f9f72f6b279ab7c4265 to your computer and use it in GitHub Desktop.
Passing list object through intent with gson.toJson and gson.fromJson
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// passing to intent: | |
b.putSerializable(BUNDLE_PARAMS, new Gson().toJson(params)); | |
// retrieving data: | |
List<KeyValueStringPair> params = new Gson().fromJson(b.getString(BUNDLE_PARAMS), new TypeToken<List<KeyValueStringPair>>(){}.getType()) | |
// model class | |
public static class KeyValueStringPair implements Serializable { | |
@SerializedName("_key") | |
public String key; | |
@SerializedName("_value") | |
public String value; | |
public KeyValueStringPair() { | |
// compulsory empty constructor | |
} | |
public KeyValueStringPair(String key, String value) { | |
this.key = key; | |
this.value = value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment