I'm trying to serialize objects with TJSONMarshal (XE4), but when the goods _recordset like My class: My task: {"type": "uTest.TFoo", "id": 1, "fields": {"FFooProp": 0}} RSF is not a serial! Can I do this serial? Or a range of TJSONMarshal In my case I just want to order _recordsets was my solution? : 1) get all _Recordset type fields: 2) Setting up of each field in the Register FieldNameList
TFoo = class private FrsFoo: _recordset; FFooProp: integer; Published asset rsFoo: _recordset Read FrsFoo FrsFoo; Property FooProp: Write FFooProp FFooProp Integer; End;
function TestSerialize: string; War Jason Marshall: TJSanmarpal; Foo: TFU; Start Jason Marshall: = TJSnarmachel. Create (TJSON Kanan. Create); Foo: = TFoo.Create; Results: = Jason Marshall. Marshall (Foo) Toasting; End; The result of:
function Test.GetRecordsetFieldsFromObject (AObject: TObject): TStringList; Var Obj: TRttiType; RTT: TR.TTXtext; Objfield: Tertiefeld; IntfObj: IInterface; RsOut: _recordset; Start the result: = TStringList.Create; Obj: = Rtti.GetType (AObject.ClassType); What Obj.GetFields to ObjField, so ObjField.FieldType.TypeKind = tkInterface so IntfObj start: = ObjField.GetValue (AObject) .AsInterface; If IntfObj.QueryInterface (_Recordset, rsOut) = 0 then the result starts. Add (ObjField.Name); RsOut: = Zero; End; End; End;
for the FieldName to be started converter and Reverter JsonMarshal.RegisterConverter (TFoo, FieldName, function (data: TObject; Field: string): TListOfStrings var Obj: TRttiType; ObjField: TRttiField; rsProp: _Recordset; strStream: TStringStream; SetLength started (results, 1); strStream: = TStringStream.Create; try Obj: = Rtti. GetType (data.ClassType); ObjField: = Obj.GetField (field); rsProp: = ObjField.GetValue (data) as .AsInterface _Recordset; rsProp.Save (TStreamAdapter.Create (strStream) IUnknown, adPersistXML); results [ 0]: = strStream data string; finally rspr W = null; strStream.Free; end; end); JsonUnmarshal.RegisterRiverter (TFoo, FieldName, Process (Data: TuboXxt; Field: String; Arajes: TLITOffStringings) ORB: TRTIPAP; Obeizfield: Treatedfield; RSprop: _Rcorset; Struff: TastingStream; RSprop Start: = Corkorset; .Create (Args [0]); Obj: = Rtti.GetType (Data classotype); ObjField: = Obj.GetField (field); strStream.Position: = 0; rsProp.Open (TStreamAdapter.Create (strStream) IUnknown in, EmptyParam, adOpenUnspecified, adLockUnspecified, 0); ObjField.SetValu E (Data, TValue.From & lt; _Recordset & gt; (rsProp); Finally; RSprop: = Zero; strStream.Free; end; end;); End;
Thursday, 15 April 2010
json - Can I serialize an interface(_recordset) with TJSONMarshal? -
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment