I am trying to deserialize a request body but need to allow one of the fields to be optional.
RequestBody {
Decimal someNumber;
}
RequestBody reqBody = (RequestBody)JSON.deserialize(req.requestBody.toString(), RequestBody.class);
MyCustomObject obj = new MyCustomObject();
obj.someNumber = reqBody.someNumber;
If the field age
is empty, it gets sent in as an empty string, and I just get a 500 Server Error
as my response. How can I allow this to just be null if it's empty?
Best Answer
do the same for all variables you want to set (look carefuly to cast each value to the proper primitive data types)
otherwise you will have to check the values instances
and properly handle each data type
Good luck!