You need to sign in to do that
Don't have an account?
CalRam
Invalid type: ContentssArray
Illegal conversion from List<Object> to List<ContentssArray>
Thanks In Advance
Apex error - Illegal conversion from List<Object> to List<ContentssArray>
global with sharing class GetObjectsAWS{ @AuraEnabled public static List<ContentssArray> GetObject(){ String jsonResponse = XMLParser.xmlToJson(res.getBody()); // String json ='Contents:{"Key": "my-third-image.jpg", "LastModified": "2009-10-12T17:50:30.000Z", "ETag": "\"1b2cf535f27731c974343645a3985328\"", "Size": "64994", "StorageClass": "STANDARD_IA", "Owner": {"ID": "75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a", "DisplayName": "mtd@amazon.com"}}'; system.debug('+++++Body is'+jsonResponse); Map<String,Object> jsonParsed =(Map<String,Object> ) JSON.deserializeUntyped(jsonResponse); Map<String,Object> content_collection = ( Map<String,Object>) jsonParsed.get('ListBucketResult'); List<Object> ContentssArray =( List<Object> ) content_collection.get('Contents'); for(Object inidividualEntries : ContentssArray){ Map<String,Object> ind = (Map<String,Object> )inidividualEntries; System.debug('Key = '+ ind.get('Key')); System.debug('Size = '+ ind.get('Size')); System.debug('---------------------------------------------'); } return ContentssArray; }Trying to dispay the JSON response in the lightnign component. Hence returning LIST in the apex controller. But getting below errors:
Invalid type: ContentssArray
Illegal conversion from List<Object> to List<ContentssArray>
Thanks In Advance
I assume you have an Object called ContentssArray based on line 5 public static List<ContentssArray> GetObject()
You then use the exact same capitalisation in your List declaration at Line 12 List<Object> ContentssArray
Makes it confusing. Yes, I know we do Account account = new Account(); but notice the capitalisation to help differentiate.
Now, to your error. It relates to the two lines mentioned. Your method is expecting to return a List of <ContentssArray> records, but you have are returning the variable ContentssArray which you have declared as a list of <Object>
You will have to change either the type of List that the method is expecting to return, or cast from Object to ContentssArray at some stage. Line 12 looks a likely candidate.
Regards
Andrew