I am passing List attribute as a String to aura action by JSON.stringify

and this is what I am getting in the apex debug --


This is a a list of JSON objects, however I am not able to deserialize into map--

I tried -

List<Map<String,Object>> lstMinorEnrolledBy = (List<Map<String,Object>>) JSON.deserialize(strMinorEnrolledBy, List<Map<String,Object>>.class);

Error message:

Apex Type unsupported in JSON: Object

  • 1
    You should be trying to deserialize into a List<Map<String,String>> Jul 8 '19 at 18:28
  • 3
    You might like to try JSON.deserializeUntyped.
    – Phil W
    Jul 8 '19 at 18:33
  • Yeah, that too! Jul 8 '19 at 18:39
  • I get this after trying your suggestions --Unexpected character ('e' (code 101)): was expecting double-quote to start field name at [line:1, column:3]
    – mvk1991
    Jul 8 '19 at 18:49
  • Strangely it goes to last debug line and I get this in debug--MVK lstMinorEnrolledBy-->({enrolledbyAdult=0032200000ADlc1AAD, minorDependent=0032200000ADltqAAD})
    – mvk1991
    Jul 8 '19 at 18:52

You just need to change the target data type to List<Map<String,String>>

This works: (checked in dev console)

String str = '[{"minorDependent":"0032200000ADltqAAD","enrolledbyAdult":"0032200000ADlc1AAD"}]';
List<Map<String,String>> lstMinorEnrolledBy = (List<Map<String,String>>) JSON.deserialize(str, List<Map<String,String>>.class);

You can use JSON.deserializeUntyped if you had a case where there was a mix of String and Decimal values:

Object[] rows = (Object[])JSON.deserializeUntyped(strMinorEnrolledBy);
for(Object row: rows) {
    Map<String, Object> values = (Map<String, Object>)row;
    // you can now access values directly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.