JSON deserializeUntyped
is causing trouble and I could not understand why it would convert a Array of data to something that is neither an array nor a similar string?
To reproduce I am executing this in Execute Anonymous Dev Console:
String s = '{ "data" : [ "powerCord", "test" ] }';
system.debug('Data String :: '+s);
Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped(s);
system.debug('Deserialized To MAP :: '+m);
system.debug('Reading Map (data) :: '+m.get('data'));
List<String> l = (List<String>)JSON.deserialize(String.valueOf(m.get('data')), List<String>.class);
system.debug('@@ '+l);
Error I get:
FATAL_ERROR System.JSONException: Unexpected character ('(' (code 40)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]
Is there something wrong in my code here?