Hi, I have a class as a parameter in a service, but the validation is not performed.
The class:
TJsonRPC = class
strict private
[Required] Fjsonrpc: String;
[MinLenght(1)] Fmethod: string;
[Required] Fparams: TObject;
[Required] Fid: string;
public
property jsonrpc: String read Fjsonrpc write Fjsonrpc;
property method: String read Fmethod write Fmethod;
property params: TObject read Fparams write Fparams;
property id: String read Fid write Fid;
end;
[ValidateParams]
[HttpPost] function JSONRPC2([Required] AJsonRPC:TJsonRPC): TStream;
function TSerGenService.JSONRPC2(AJsonRPC: TJsonRPC): TStream;
var
User: IUserIdentity;
begin
//User Authorization;
if AJsonRPC.Jsonrpc <> '2.0' then
raise EXDataHttpForbidden.Create('JsonRPC non conforme');
result:=TstringStream.Create('test');
end;
AJsonRpc is not validated on receieve request if one property is empty.
I expect an exception first. Am I doing something wrong?
Thanks
Xdata documentation:
When a parameter is class, then the object itself will also be validated, i.e., all the mapped
members will also have the validation attributes applied:
In the above example, when AcceptFoo is invoked, XData will apply the Required validation to
it. If Foo is nil , the request will be rejected. But also, even if Foo object is provided, the
request will only be accepted if the Id property is positive, and Name property is not longer
than 10 characters.
For example, if the following JSON is sent to the endpoint:
The endpoint will answer with a 400 Bad Request response including the following detailed
content:
TFoo = class
strict private
[Range(1, MaxInt)] FId: Integer;
[MaxLength(10)] FName: string;
public
property Id: Integer read FId write FId;
property Name: string read FName write FName;
end;
{...}
[ValidateParams] procedure AcceptFoo([Required] Foo: TFoo);