You are not logged in.
Dear all,
I want to create service of TServiceCoupon and implement TServiceCoupon.Get to return Json result of TResponseJson<TSQLCouponMst>
But during runtime, I got the exception "unexcepted type TResponseJson<DataMode.TSQLCouponMst> - use TJONSerializer.RegisterCustomSerializer()
I think I got something wrong in coding/definition and no need to write custom serializer.
Would anyone have any comment for my thinking?
Thank a lot!
Regards,
HK City
TResponseJson<T: class> = class (TObjectList<T>)
private
Fdata: TObjectList<T>;
Fsuccess: boolean;
Fmsg: String;
procedure Setdata(const Value: TObjectList<T>);
published
constructor Create;
property success : boolean read Fsuccess write Fsuccess;
property msg : String read Fmsg write Fmsg;
property data: TObjectList<T> read Fdata write Setdata;
end;
TSQLCouponMst = class(TSQLRecord)
protected
fidCouponMst: Int64;
fshopName: RawUTF8;
fcouponDesc: RawUTF8;
feffDateDesc: RawUTF8;
fcouponFileName: RawUTF8;
fcrtDate: TDateTime;
fcrtBy: RawUTF8;
published
property idCouponMst: Int64 read fidCouponMst write fidCouponMst;
property shopName: RawUTF8 index 50 read fshopName write fshopName;
property couponDesc: RawUTF8 index 200 read fcouponDesc write fcouponDesc;
property effDateDesc: RawUTF8 index 50 read feffDateDesc write feffDateDesc;
property couponFileName: RawUTF8 index 50 read fcouponFileName write fcouponFileName;
property crtDate: TDateTime read fcrtDate write fcrtDate;
property crtBy: RawUTF8 index 50 read fcrtBy write fcrtBy;
end;
TServiceCoupon = class(TInterfacedObject, ICoupon)
public
procedure Get(const id: integer; out response : TResponseJson<TSQLCouponMst>);
end;
Offline
Using such a generic TResponseJson<T: class> type is not supported yet.
And it sounds a bit complicated to me to create such a "response" type over our service interfaces.
It is the purpose of our service implementation to process responses, and offer directly-end user types.
IMHO the easiest is simply to use a RawJSON kind of parameter, then use good old TSQLTableJson and its TSQLTable.ToObjectList<T>: TObjectList<T> method, if you want to consume the result with generics.
Offline
I will try to your suggested approach. Thank for your advice
Offline
Thank ab. Finally I use this method to output for my json structure
procedure Get(const id: integer; out success: boolean; out msg: string; out data: RawJSON);
Offline