2

I am trying to create a JSON array but when I try to run the code I am getting an error

System.UnexpectedException: Salesforce System Error: 884193503-1014 (-1834458735) (-1834458735)

My code :

public void getGenerateJSON(Map<Integer,list<ConfiguredItemsServiceImpl.ImportIdCodeWrapperClass>> ConfiguredItemWrapper){
    JSONGenerator gen = JSON.createGenerator(true);
    System.debug('Configured Item Wrapper ' + ConfiguredItemWrapper);

    for(Integer num : ConfiguredItemWrapper.keySet()){
        for(ConfiguredItemsServiceImpl.ImportIdCodeWrapperClass ConfiguredItemWrapperinfo : ConfiguredItemWrapper.get(num)){
            if(num == 0){
                 gen.writeStartObject();
                    gen.writeFieldName('ProductConfiguration');

                    gen.writeStartObject();
                        gen.writeStringField('Name', ConfiguredItemWrapperinfo.configuredItem.Name);
                        gen.writeStringField('ID', ConfiguredItemWrapperinfo.configuredItem.ID);
                        gen.writeNumberField('Level', ConfiguredItemWrapperinfo.configuredItem.Level__c);
                        if(ConfiguredItemWrapperinfo.configuredItem.Label__c != null)
                            gen.writeStringField('Label', ConfiguredItemWrapperinfo.configuredItem.Label__c);        
                        if(ConfiguredItemWrapperinfo.code != null)
                            gen.writeStringField('code', ConfiguredItemWrapperinfo.code);

                    gen.writeFieldName('ProjectDetails');
                    gen.writeStartObject();
                        gen.writeStringField('Date', String.valueof(date.today()));
                        gen.writeStringField('ID', ConfiguredItemWrapperinfo.configuredItem.Basic_Config_Info__c);      
                        //gen.writeStringField('Name', ConfiguredItemWrapperinfo.configuredItem.Basic_Config_Info__r.Name);
                        gen.writeStringField('Name', ConfiguredItemWrapperinfo.configuredItem.Name);

                        gen.writeFieldName('Output');
                        gen.writeStartObject();
                            gen.writeStringField('FolderPath', 'XYZ Path');
                            gen.writeStringField('FileName', 'XYZ NAME');
                        gen.writeEndObject();
                    gen.writeEndObject();





                jsonString += gen.getAsString();
            }else if(num == 1){
                gen.writeStartObject();
                    gen.writeFieldName('Assembly');
                    gen.writeStartArray();
                        gen.writeStartObject();
                            gen.writeStringField('ModelCode', 'Model code 123456');
                            gen.writeStringField('Description', 'Description 123456');
                            //System.debug('Map information in assembly' +ConfiguredItemWrapper.get(num));
                        gen.writeEndObject();
                    gen.writeEndArray();
                gen.writeEndObject();
                jsonString += gen.getAsString();
            }

        }
    }  

    gen.writeEndObject();
    gen.writeEndObject();
    jsonString += gen.getAsString();
    System.debug('JSON Result in string ' + jsonString);
}

When the same code by commenting the Array methods it works. But issue stands when I try to convert it into array. Do anyone have any solution on this issue. The issue is at line no 52 just below else if(num == 1) on gen.writeStartObject(); Do I need to log a case with salesforce. Is this issue from background. As mention here Please guide me how can I fix this issue.

  • 2
    try enclosing content between array, into object ; gen.writeStartArray();gen.writeStartObject(); //---// gen.writeEndObject();gen.writeEndArray(); – highfive Sep 4 '15 at 13:31
  • Thansk @highfive tried it but still getting the same error. – Anu Sep 4 '15 at 13:43
  • may be some issue while iterating through the loop? Can you try it with may be checking for field values or with known specific data? – highfive Sep 4 '15 at 18:05
2

Because you are adding key value pairs inside the array, you should start and end object..See the below code:

Check this link on how arrays are defined in JSON : http://www.objgen.com/json?demo=true

String jsonString = '';
JSONGenerator gen = JSON.createGenerator(true);
for(Account accObj : [SELECT Id,Name,Phone FROM Account WHERE Id = '001Z023456ztasN' LIMIT 1]){
    gen.writeStartObject();
    gen.writeFieldName('attendees');

    gen.writeStartArray();

    gen.writeStartObject();
    gen.writeStringField('Name', accObj.Name);
    gen.writeStringField('ID', accObj.ID);
    //gen.writeNumberField('Level', accObj.Phone);
    gen.writeEndObject();

    gen.writeEndArray();
    gen.writeEndObject();
    jsonString += gen.getAsString();
}

System.debug('JSON Result in string ' + jsonString);

JSON Result in string { "attendees" : [ { "Name" : "test lead Company", "ID" : "001Z0123450ztasNIAQ" } ] }

| improve this answer | |
  • when i tried the code getting an error : System.UnexpectedException: Salesforce System Error: 884193503-1014 (-1834458735) (-1834458735). Do this error related to any issue in background of salesforce. Do I need to log a case with salesforce for this issue. developer.salesforce.com/forums/?id=906F000000090ZtIAI – Anu Sep 5 '15 at 6:04
  • Do you know after which line it is throwing error? – javanoob Sep 5 '15 at 6:07
  • have updated my code the error is at line 52 just below 'else if(num == 1)'. on gen.writeStartObject();. – Anu Sep 5 '15 at 6:11
  • @Anu..Everything seem fine.May be you can open case with salesforce as mentioned in the other post...sorry couldn't help much on this – javanoob Sep 5 '15 at 15:52
0

Fixed the issue by adding gen.writeFieldName('attendees'); above gen.writeStartObject();.

| improve this answer | |

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.