function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sumit dsumit d 

Malformed JSON: Expected '[' at the beginning of List/Set in test class

Hi All,
 I have created a test class which is giving me following error:-Malformed JSON: Expected '[' at the beginning of List/Set 
How to resolve it ?
My class and test class is given below:- 
public with sharing class ParticipationController {
   @AuraEnabled
public static string updateParticipations(Object data) {
    List<bre__BR_Participation__c> ParticipationsForUpdate = (List<bre__BR_Participation__c>) JSON.deserialize(
         JSON.serialize(data),
         List<bre__BR_Participation__c>.class
    );
    try {
        update ParticipationsForUpdate;
        return 'Success: Participation updated successfully';
    }
    catch (Exception e) {
        return 'The following exception has occurred: ' + e.getMessage();
    }
}
}

My test class is given below:-
@istest
public with sharing class ParticipationControllerTest {
        static testmethod void updateParticipationTest() {
        bre__BR_Event__c ev = new bre__BR_Event__c();
        ev.bre__Start_Date__c = System.today();
        insert ev;
        bre__BR_Participation__c data = new bre__BR_Participation__c();
        data.bre__BR_Event__c = ev.id;
        insert data;
        test.startTest();
        data.Participated__c = true;
        update data;
        ParticipationController.updateParticipations(data);
        test.stopTest();
    }
}
 
VinayVinay (Salesforce Developers) 
Hi Sumit,

Data is already a string you no need to change this and try to remove below line and see.
 
JSON.serialize(data),

Thanks,