I have the following json string:
String config = "{contact:{\"FIRSTNAME\":\"C_FirstName\",\"EMAIL\":\"C_EmailAddress\"}, "
+ "customobject:{\"CUSTOM_FIELD1\":\"Custom_Field__11\","
+ "\"FIRSTNAME\":\"First_Name1\",\"EMAIL\":\"Email_Address1\"}}";
I need to extract each object, i.e., contact and customobject as a String so the final result should be:
String contact = "{\"FIRSTNAME\":\"C_FirstName\",\"EMAIL\":\"C_EmailAddress\"}";
String customobject = "{\"CUSTOM_FIELD1\":\"Custom_Field__11\","
+ "\"FIRSTNAME\":\"First_Name1\",\"EMAIL\":\"Email_Address1\"}";
It is required to use Gson for this so I'm trying the following:
Map<String, String> map = gson.fromJson(config, new TypeToken<Map<String,Object>>(){}.getType());
String json = map.get("contact").toString();
But I get the following error:
java.lang.ClassCastException: com.google.gson.internal.StringMap cannot be cast to java.lang.String
What is the proper way to achieve this ?