Consider the following class:
public class Caps {
public Sett SETTINGS {get;set;}
}
public class Sett {
public string foo {get;set;}
}
When I POST the following JSON:
{"SETTINGS":{"foo":"bar"}}
To my own REST class:
...
@HttpPost
global static void doPost(Caps change) {
}
I get 400 Bad Request:
[
{
"message": "Unexpected parameter encountered during deserialization: SETTINGS at [line:1, column:14]",
"errorCode": "JSON_PARSER_ERROR"
}
]
However the exact same JSON can be de-serialised as follows:
String s = '{"SETTINGS":{"foo":"bar"}}';
Caps c = (Caps)JSON.deserialize(s, Caps.class);
system.debug(c);
As a workaround I can do the de-serialisation in my REST class:
@HttpPost
global static ZRest.ZRestResponse doPost() {
String req = RestContext.request.requestBody.toString();
Caps change = (Caps)JSON.deserialize(req, Caps.class);
}
This works fine and I get 200.
The question is why doesn't the standard REST de-serialisation of parameters work?
PS: I read possible duplicate questions but they only seem to offer a workaround or the same string in a different format (newlines, indents) which doesn't solve my issue at all.