I've set up an @RestResource
class for receiving an external JSON webhook through an @httppost
class, which is working great, but when retrieving the content of the request through RestContext.request.requestBody.toString()
, escaped special characters within JSON strings, specifically \"
, appear to be unescaping to "
, which then prevents JSON.deserialize()
from correctly parsing the string.
Example code:
@RestResource(urlMapping='/rest')
global class listener {
public class parseJSON {
public string field;
}
@HttpPost
global static void postmethod(){
JSON.deserialize(RestContext.request.requestBody.toString(), parseJSON.class);
}
}
In this example, a request body of:{"field":"value"}
will succeed.
However, a request body of {"field":"value \" "}
, produces the following error:
FATAL_ERROR System.JSONException: Unexpected character ('"' (code 34)): was expecting comma to separate OBJECT entries at [line:1, column:20]`
Am I approaching/understanding this correctly?