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
JagmohanJagmohan 

JSON.serialize results in System.JSONException: Salesforce System Error

I'm trying to serialize an object of Map<String, Object> type into json string using JSON.serialize method, but it keeps crashing. Here is stacktrace for one such execution
 
34.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
12:24:15.064 (64561656)|EXECUTION_STARTED
12:24:15.064 (64624655)|CODE_UNIT_STARTED|[EXTERNAL]|06690000005iyPH|VFRemote: TestController invoke(saveForm)
12:24:15.064 (64670374)|SYSTEM_MODE_ENTER|true
12:24:15.066 (66479728)|METHOD_ENTRY|[1]|01p900000072RHd|TestController.TestController()
12:24:15.066 (66578736)|SYSTEM_MODE_ENTER|false
12:24:15.066 (66600814)|SYSTEM_MODE_EXIT|false
12:24:15.066 (66634140)|METHOD_EXIT|[1]|TestController
12:24:15.066 (66662920)|SYSTEM_MODE_ENTER|false
12:24:15.067 (67044839)|SYSTEM_METHOD_ENTRY|[5]|String.valueOf(Object)
12:24:15.067 (67514273)|SYSTEM_METHOD_EXIT|[5]|String.valueOf(Object)
12:24:15.067 (67578792)|SYSTEM_METHOD_ENTRY|[5]|System.debug(ANY)
12:24:15.067 (67781555)|USER_DEBUG|[5]|DEBUG|## data FormData:[config={baseobjects=[{name=Contact}, {name=Account}], pages=[{rows=[{name=Account Row}, {name=Contact Row}]}]}]
12:24:15.067 (67812570)|SYSTEM_METHOD_EXIT|[5]|System.debug(ANY)
12:24:15.067 (67897852)|SYSTEM_METHOD_ENTRY|[6]|TestController.FormData.__sfdc_config()
12:24:15.067 (67963920)|SYSTEM_METHOD_EXIT|[6]|TestController.FormData.__sfdc_config()
12:24:15.068 (68111137)|SYSTEM_METHOD_ENTRY|[6]|System.JSON.serialize(Object)
12:24:15.076 (76852763)|SYSTEM_METHOD_EXIT|[6]|System.JSON.serialize(Object)
12:24:15.076 (76889916)|SYSTEM_MODE_EXIT|false
12:24:15.077 (77131149)|FATAL_ERROR|System.JSONException: Salesforce System Error: 2043493233-942 (717264018) (717264018)

(System Code)
Class.TestController.saveForm: line 6, column 1
12:24:15.077 (77204398)|CODE_UNIT_FINISHED|VFRemote: TestController invoke(saveForm)
12:24:15.079 (79569009)|EXECUTION_FINISHED


Visualforce Page
 
<apex:page controller="TestController" applyBodyTag="false">
    <head>
        <title>Test</title>
        <script type="text/javascript">
            function buildFormData() {
                var form = {};
                form.config = {};
                form.config.pages = [];
                var page = {};
                page.rows = [];
                var row = {name: 'Account Row'};
                page.rows.push(row);
                row = {name: 'Contact Row'};
                page.rows.push(row);
                form.config.pages.push(page);

                form.config.baseobjects = [];
                var baseObj = {name: 'Contact'};
                form.config.baseobjects.push(baseObj);
                baseObj = {name: 'Account'};
                form.config.baseobjects.push(baseObj);
                return form;
            }

            function saveForm(){
                var formData = buildFormData();
                Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.TestController.saveForm}', 
                    formData, function(result, event) {
                        if(event.status) {
                            console.log(result);
                        } else {
                            alert('Error: ' + event.message);
                        }
                    }, {buffer: false, escape: false, timeout: 30000}
                );
            }
        </script>
    </head>
    <body>
        <div>
            <h2>Send object and get json string.</h2>
            <br />
            <button onclick="saveForm()">Save Form</button>
        </div>
    </body>
</apex:page>



Controller
 
global with sharing class TestController {

    @RemoteAction
    global static String saveForm(FormData data) {
        System.debug('## data ' + data.config);
        // it crashes on JSON.serialize
        return JSON.serialize(data.config);
    }

    global class FormData {
        public Map<String, Object> config {get; set;}

        public FormData() {
            config = new Map<String, Object>();
        }
    }
}



The following error occurs on JSON.serialize call
FATAL_ERROR|System.JSONException: Salesforce System Error: 2043493233-942 (717264018) (717264018)

Any help is appreciated.
Thanks