In Salesforce if you try and do this:
JSON.serialize(data);
where data
is an instance of a global Apex class in another managed package it will fail.
This seems like a completely arbitrary and pointless limitation, since all the global fields can be accessed anyway. So why did Salesforce do this, and is there any alternative?
Best Answer
There is a @JsonAccess annotation. Check this:
https://releasenotes.docs.salesforce.com/en-us/summer20/release-notes/rn_apex_JsonAccessAnnotation.htm
This annotation has 2 parameters: serializable & deserializable with this 4 options:
Example:
@JsonAccess(serializable='never' deserializable='sameNamespace')
public class Foo {}