[SalesForce] How to pass LIST custom setting list(array) from client side to server side controller in lightning

I have created an array of list custom setting in JS controller of lightning component. When I call apex controller method and pass this array, inside controller its value comes as empty. However, when I pass a single record of the same custom setting, that value is accessed successfully and I can see all its field values.

I think that there is some way that I am unknown in Javascript where you can send an array of list custom setting to apex. Does anybody has idea about this?

My code of lightning component helper:

//"setting" is the list custom setting record passed as attribute in an event
//"updatedCustomSettingList" is the attribute in this component of type "list" used to  fill everytime a record is sent to this component
createSettingList : function(component, event){
    var setting=event.getParam("setting");
    var updatedCustomSettingList = [];
    updatedCustomSettingList=component.get("v.updatedCustomSettingList");
    updatedCustomSettingList.push({
        value : setting
    });
    component.set("v.updatedCustomSettingList", updatedCustomSettingList);
}

Component:

<aura:attribute name="updatedCustomSettingList" type="list" />

Apex controller method:

 public static void updateEditedValues(List<TimeTrackerConfigSettings__c> settingList){
    system.debug('inside method, setting returned is: '+ settingList); //value comes as {}

Best Answer

I've found the best way to get around this sort of issue is to serialize your setting list in the Javascript controller and deserialize in your Apex Controller.

Something like this:

action.setParams({
  "jsonParams": JSON.stringify(yourArray)
});
action.setCallback(this, function(response) {.... etc

In the controller, make sure you change the param type to string and deserialize like so:

@AuraEnabled
public static String saveData(String jsonParams) {

    List<TimeTrackerConfigSettings__c> settings;
    try {
        settings = (List<TimeTrackerConfigSettings__c>)JSON.deserialize(jsonParams, List<TimeTrackerConfigSettings__c>.class);
    } catch (Exception e) {
        //handle error
    }

    //process settings as per normal