Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Json marshal TGUID value within record (XE7)


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 0
Tobias Schreck

Posts: 1
Registered: 2/5/15
Json marshal TGUID value within record (XE7)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 15, 2015 4:15 AM
Hello,
I have a problem with converting a TGUID value to a JSON string. The following variant is working:

{$METHODINFO ON}
TTest = class (TObject)
private
[JSonReflect (ctString, rtString, TGuidInterceptor, nil, True)]
FID: TGUID;
public
property ID: TGUID read FID write FID;
end;
{$METHODINFO OFF}
(..)
S := TJson.ObjectToJsonString (TestObj);

The marshaller enters the TGuidInterceptor, where the value is converted to a string.

Mostly I have record types containing TGUID values, so I have something like that;

type
TRec = record
[JSonReflect (ctString, rtString, TGuidInterceptor, nil, True)]
FID: TGUID;
end;

TTest = class (TObject)
private
FRec: TRec;
public
property Rec: TRec read FRec;
end;
(..)
S := TJson.ObjectToJsonString (TestObj);

In this case the TGuidInterceptor isn't called, and the marshaller tries to convert the TGUID as a record value and raises an exception when converting the property D4 (byte array) of TGUID.

Does anybody have an idea how to solve this situation?

Many thanks,
Tobias
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02