Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have been using JSON.Serialize method extensively in one of customer's project. Today salesforce has started rolling out Spring '13 release on sandboxes. My customer's sandbox( cs11) is not listed on https://trust.salesforce.com/trust/maintenance/ but still Spring '13 is available in this sandbox.

I have noticed a change that if I serialize a sObject, Json Serializer doesn't return fields with null value in json. Before Spring '13 release it was working fine.

If this was a needed change to reduce size of serialized json, Salesforce should have made this version specific change or a overloaded method to keep backward compatibility. It has broken 30%-40% of my code that I will need to rewrite.

Salesforce please undo this change.

Current output: [ { "attributes": { "type": "ABC_c", "url": "/services/data/v27.0/sobjects/ABC_c/xxxx" }, "Active__c": false, "Id": "XXXX", "Name": "ABC" }, ]

Old output: [ { "attributes": { "type": "ABC_c", "url": "/services/data/v27.0/sobjects/ABC_c/xxxx" }, "Active_c": false, "FirstName_c": null, "Id": "XXXX", "Name": "ABC" }, ]

share|improve this question
1  
Can you just make the class deprecated to version 26.0 and try.I just verified and yes JSON.serialise() no more returns null values –  Mohith Shrivastava Jan 12 '13 at 14:59
1  
Also only one way i can think of now is if the value is null you may need to explicitly say value=null to get back the same in JSON Account acc=[Select Id,name,Name_Suffix__c from Account where id='001W0000007Ky0Z']; if(acc.Name_Suffix__c!=null) {acc.Name_Suffix__c=null; }System.debug('JSON STRING'+acc); –  Mohith Shrivastava Jan 12 '13 at 16:07
3  
As Mohith says, all changes can be version specific - you should be able to mark the class as API 26.0 and have nulls encoded. –  metadaddy Jan 12 '13 at 17:44
    
I am using version 25.0 on my classes still it is not returning null fields in JSON. Can someone from Salesforce Engineering team confirm this issue and expected behavior of this during final roll-out on production instances. –  user1203 Jan 13 '13 at 5:18
    
Stackexchange note; it seems that you have created two accounts on salesforce.stackexchange.com, it would be best to use one. As an answer to your question, to get input from the Salesforce team, I think it would be best to log a case. –  Lex Jan 13 '13 at 10:25

2 Answers 2

The Apex development team changed the behavior of the JSON serialization in response to several customer issues.

As you are aware, we will typically version changes to the system behavior where possible, in order to protect backward compatibility. There are situations in which we do not version behavior, however. We made an assumption that JSON parsers would not have an issue not receiving null values, since the information received is not relevant. It's like the junk mail you reflexively throw out when sifting through your mail.

As per your post, it's clear that some parsing strategies depend on null values being included in the JSON output. We apologize that our assumption was incorrect, and that your integration and others were unable to operate with the new version.

We have undone the change for the Spring '13 release. To support the original customer cases that prompted these changes, we will version in the originally intended fix in the Summer release.

Thanks,

Josh Kaplan

Product Manager, Apex Code

share|improve this answer
1  
Was this added? still not able to get null values with version 28? Am I missing something? –  Chirag Mehta Aug 5 '13 at 6:31

Were you able to fix this problem? We are also getting the same problem. If we tried to change the API version of web service, it doesn't reflect while calling web service.

Due to that we need to change our code and put the condition to handle no fields. Which will take much processing on mobile device. Because we are calling this web service from mobile device.

Thanks and Regards.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.