Skip to main content
Commonmark migration
Source Link

Sadly, this means that you'll need to use either a JSONParser or a generic Object that you can get from JSON.deserializeUntyped.

In summary, that means you'll ultimately need to do a bit more heavy lifting than if there were no reserved keywords. I prefer to use JSON.deserializeUntyped, personally, but this means you'll need to know what kind of data is coming in. The initial return value might be a List<Object> or a Map<String, Object>, which you can test for using instanceOf or a simple try-catch block. From there, you can recursively examine each Object to see if it is a list or a map, and parse the results.


###Example Code

Example Code

@HttpPost global static void handlePostAction() { Object jsonObj = JSON.deserializeUntyped(RestContext.request.requestBody); // Do something with jsonObj, which may be a list or map } 

Sadly, this means that you'll need to use either a JSONParser or a generic Object that you can get from JSON.deserializeUntyped.

In summary, that means you'll ultimately need to do a bit more heavy lifting than if there were no reserved keywords. I prefer to use JSON.deserializeUntyped, personally, but this means you'll need to know what kind of data is coming in. The initial return value might be a List<Object> or a Map<String, Object>, which you can test for using instanceOf or a simple try-catch block. From there, you can recursively examine each Object to see if it is a list or a map, and parse the results.


###Example Code

@HttpPost global static void handlePostAction() { Object jsonObj = JSON.deserializeUntyped(RestContext.request.requestBody); // Do something with jsonObj, which may be a list or map } 

Sadly, this means that you'll need to use either a JSONParser or a generic Object that you can get from JSON.deserializeUntyped.

In summary, that means you'll ultimately need to do a bit more heavy lifting than if there were no reserved keywords. I prefer to use JSON.deserializeUntyped, personally, but this means you'll need to know what kind of data is coming in. The initial return value might be a List<Object> or a Map<String, Object>, which you can test for using instanceOf or a simple try-catch block. From there, you can recursively examine each Object to see if it is a list or a map, and parse the results.


Example Code

@HttpPost global static void handlePostAction() { Object jsonObj = JSON.deserializeUntyped(RestContext.request.requestBody); // Do something with jsonObj, which may be a list or map } 
added 243 characters in body
Source Link
sfdcfox
  • 1
  • 21
  • 485
  • 850

Sadly, this means that you'll need to use either a JSONParser or a generic Object that you can get from JSON.deserializeUntyped.

In summary, that means you'll ultimately need to do a bit more heavy lifting than if there were no reserved keywords. I prefer to use JSON.deserializeUntyped, personally, but this means you'll need to know what kind of data is coming in. The initial return value might be a List<Object> or a Map<String, Object>, which you can test for using instanceOf or a simple try-catch block. From there, you can recursively examine each Object to see if it is a list or a map, and parse the results.


###Example Code

@HttpPost global static void handlePostAction() { Object jsonObj = JSON.deserializeUntyped(RestContext.request.requestBody); // Do something with jsonObj, which may be a list or map } 

Sadly, this means that you'll need to use either a JSONParser or a generic Object that you can get from JSON.deserializeUntyped.

In summary, that means you'll ultimately need to do a bit more heavy lifting than if there were no reserved keywords. I prefer to use JSON.deserializeUntyped, personally, but this means you'll need to know what kind of data is coming in. The initial return value might be a List<Object> or a Map<String, Object>, which you can test for using instanceOf or a simple try-catch block. From there, you can recursively examine each Object to see if it is a list or a map, and parse the results.

Sadly, this means that you'll need to use either a JSONParser or a generic Object that you can get from JSON.deserializeUntyped.

In summary, that means you'll ultimately need to do a bit more heavy lifting than if there were no reserved keywords. I prefer to use JSON.deserializeUntyped, personally, but this means you'll need to know what kind of data is coming in. The initial return value might be a List<Object> or a Map<String, Object>, which you can test for using instanceOf or a simple try-catch block. From there, you can recursively examine each Object to see if it is a list or a map, and parse the results.


###Example Code

@HttpPost global static void handlePostAction() { Object jsonObj = JSON.deserializeUntyped(RestContext.request.requestBody); // Do something with jsonObj, which may be a list or map } 
Source Link
sfdcfox
  • 1
  • 21
  • 485
  • 850

Sadly, this means that you'll need to use either a JSONParser or a generic Object that you can get from JSON.deserializeUntyped.

In summary, that means you'll ultimately need to do a bit more heavy lifting than if there were no reserved keywords. I prefer to use JSON.deserializeUntyped, personally, but this means you'll need to know what kind of data is coming in. The initial return value might be a List<Object> or a Map<String, Object>, which you can test for using instanceOf or a simple try-catch block. From there, you can recursively examine each Object to see if it is a list or a map, and parse the results.