Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit6;
- interface
- uses
- MVCFramework.Serializer.Commons, Rtti,
- MVCFramework.Serializer.Intf,
- MVCFramework, MVCFramework.RestClient, MVCFramework.RESTClient.Intf, MVCFramework.RestAdapter, MVCFramework.Commons, MVCFramework.Nullables, MVCFramework.Serializer.JsonDataObjects.NullableTypes,
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
- type
- TForm6 = class(TForm)
- procedure FormCreate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form6: TForm6;
- type
- TSkipableString = class
- end;
- TCouchDb = class
- private
- f_Id: string;
- f_Rev: string;
- public
- property _id: string read f_Id write f_Id;
- property _rev: string read f_Rev write f_Rev;
- end;
- TTest = class(TCouchDb)
- private
- fName: TSkipableString;
- fAge: NullableInt32;
- public
- constructor create;
- property name: TSkipableString read fName write fName;
- property age: NullableInt32 read fAge write fAge;
- end;
- ICouchDb = interface(IInvokable)
- ['{4605A9AA-04C8-4309-9A69-B7890920DAA4}']
- [RestResource(HttpGet, '/{database}/{id}')]
- // [MVCProduces('application/json')]
- [MVCConsumes('application/json')]
- // [Mapping(TTest)]
- function Get([Param('database')]database: string; [Param('id')]id: string): TTest;
- [RestResource(HttpPut, '/{database}/{id}')]
- [MVCProduces('application/json')]
- [MVCConsumes('application/json')]
- // [Mapping(TTest)]
- function Update([Param('database')]database: string; [Param('id')]id: string; [Body]body: TTest): TTest;
- end;
- TSkipableStringSerializer = class(TInterfacedObject, IMVCTypeSerializer)
- public
- procedure SerializeAttribute(const AElementValue: TValue; const APropertyName: string; const ASerializerObject: TObject; const AAttributes: TArray<TCustomAttribute>);
- procedure SerializeRoot(const AObject: TObject; out ASerializerObject: TObject; const AAttributes: TArray<TCustomAttribute>; const ASerializationAction: TMVCSerializationAction = nil);
- procedure DeserializeAttribute(var AElementValue: TValue; const APropertyName: string; const ASerializerObject: TObject; const AAttributes: TArray<TCustomAttribute>);
- procedure DeserializeRoot(const ASerializerObject: TObject; const AObject: TObject; const AAttributes: TArray<TCustomAttribute>);
- end;
- implementation
- {$R *.dfm}
- var
- gRestClient: IMVCRESTClient;
- gCouchDb: ICouchDb;
- procedure TForm6.FormCreate(Sender: TObject);
- begin
- var lRestAdapter := TRestAdapter<ICouchDb>.Create;
- gRestClient := TMVCRESTClient.Create.BaseURL('http://192.168.1.4', 5984);
- var ss := TSkipableStringSerializer.Create;
- gRestClient.Serializer.RegisterTypeSerializer(TypeInfo(TSkipableString), ss);
- // gRestClient.RegisterTypeSerializer(TypeInfo(TSkipableString), ss);
- // gRestClient.Serializer
- gRestClient.SetBasicAuthorization('admin','b19246');
- gCouchDb := lRestAdapter.Build(gRestClient);
- var ans := gCouchDb.Get('mytest', 'id');
- ans.age.value := ans.age.value + 1;
- // ans.name := '';
- var repl := gCouchDb.Update('mytest', 'id', ans);
- if ans._id = repl._id then
- now;
- end;
- { TSkipableStringSerializer }
- procedure TSkipableStringSerializer.DeserializeAttribute(var AElementValue: TValue; const APropertyName: string; const ASerializerObject: TObject; const AAttributes: TArray<TCustomAttribute>);
- begin
- end;
- procedure TSkipableStringSerializer.DeserializeRoot(const ASerializerObject, AObject: TObject; const AAttributes: TArray<TCustomAttribute>);
- begin
- end;
- procedure TSkipableStringSerializer.SerializeAttribute(const AElementValue: TValue; const APropertyName: string; const ASerializerObject: TObject; const AAttributes: TArray<TCustomAttribute>);
- begin
- end;
- procedure TSkipableStringSerializer.SerializeRoot(const AObject: TObject; out ASerializerObject: TObject; const AAttributes: TArray<TCustomAttribute>; const ASerializationAction: TMVCSerializationAction);
- begin
- end;
- { TTest }
- constructor TTest.create;
- begin
- fName := TSkipableString.Create;
- end;
- end.
Add Comment
Please, Sign In to add comment