You need to sign in to do that
Don't have an account?
Lawrence-Accenture
JSON.serialize() includes null values for Apex objects
When serializing Apex objects, JSON.serialize() still includes null class variables even though the documentation seems to claim this was fixed back in Apex version 28. (I've tested with versions up to the current version -- 36)
Example Apex class:
Any suggestions on how to "fix" this?
Thanks,
-L
Example Apex class:
public with sharing class xtmp_TestJSON { public String SomeText; public String SomeOtherText; }and test JSON.serialize() using:
xtmp_TestJSON req = new xtmp_TestJSON(); req.SomeText = 'Hi'; System.debug('====> data: ' + JSON.serialize(req));Output is:
====> data: {"SomeText":"Hi","SomeOtherText":null}
Any suggestions on how to "fix" this?
Thanks,
-L
Have "null" can be a problem when you start to use the serialized json in a callout. You can get error from the receiver.
My suggestion is to use JSON.serialize(req,true); the second parameter suppress the nulls.
-L