you can also try GSON
library. It is fast and easy to use.
The Below wrapper class will make your job even more easy
public class ConvertJsonToObject {
private static Gson gson = new GsonBuilder().create();
public static final <T> T getFromJSON(String json, Class<T> clazz) {
return gson.fromJson(json, clazz);
}
public static final <T> String toJSON(T clazz) {
return gson.toJson(clazz);
}
}
All you need to do is
Map<String, String> testMap = new HashMap<String, String>();
testMap .put("1", "abc");
testMap .put("2", "ezc");
testMap .put("3", "afc");
testMap .put("4", "cvc");
String json = ConvertJsonToObject.toJSON(testMap);
and you can easily get your original Object
back on the other side
Map<String, String> newTestMap = ConvertJsonToObject.getFromJSON(json,Map.class);