diff --git a/samples/commons/BusinessObjectsU.pas b/samples/commons/BusinessObjectsU.pas
new file mode 100644
index 00000000..6daf577d
--- /dev/null
+++ b/samples/commons/BusinessObjectsU.pas
@@ -0,0 +1,108 @@
+unit BusinessObjectsU;
+
+interface
+
+uses
+ ObjectsMappers;
+
+type
+ TPerson = class
+ private
+ FLastName: String;
+ FDOB: TDate;
+ FFirstName: String;
+ FMarried: boolean;
+ procedure SetDOB(const Value: TDate);
+ procedure SetFirstName(const Value: String);
+ procedure SetLastName(const Value: String);
+ procedure SetMarried(const Value: boolean);
+ public
+ property FirstName: String read FFirstName write SetFirstName;
+ property LastName: String read FLastName write SetLastName;
+ property DOB: TDate read FDOB write SetDOB;
+ property Married: boolean read FMarried write SetMarried;
+ end;
+
+ [MapperJSONNaming(JSONNameLowerCase)]
+ TCustomer = class
+ private
+ FName: String;
+ FAddressLine2: String;
+ FAddressLine1: String;
+ FContactFirst: String;
+ FCity: String;
+ FContactLast: String;
+ procedure SetAddressLine1(const Value: String);
+ procedure SetAddressLine2(const Value: String);
+ procedure SetCity(const Value: String);
+ procedure SetContactFirst(const Value: String);
+ procedure SetContactLast(const Value: String);
+ procedure SetName(const Value: String);
+ public
+ property Name: String read FName write SetName;
+ [MapperTransient]
+ property ContactFirst: String read FContactFirst write SetContactFirst;
+ [MapperTransient]
+ property ContactLast: String read FContactLast write SetContactLast;
+ property AddressLine1: String read FAddressLine1 write SetAddressLine1;
+ property AddressLine2: String read FAddressLine2 write SetAddressLine2;
+ property City: String read FCity write SetCity;
+ end;
+
+implementation
+
+{ TPerson }
+
+procedure TPerson.SetDOB(const Value: TDate);
+begin
+ FDOB := Value;
+end;
+
+procedure TPerson.SetFirstName(const Value: String);
+begin
+ FFirstName := Value;
+end;
+
+procedure TPerson.SetLastName(const Value: String);
+begin
+ FLastName := Value;
+end;
+
+procedure TPerson.SetMarried(const Value: boolean);
+begin
+ FMarried := Value;
+end;
+
+{ TCustomer }
+
+procedure TCustomer.SetAddressLine1(const Value: String);
+begin
+ FAddressLine1 := Value;
+end;
+
+procedure TCustomer.SetAddressLine2(const Value: String);
+begin
+ FAddressLine2 := Value;
+end;
+
+procedure TCustomer.SetCity(const Value: String);
+begin
+ FCity := Value;
+end;
+
+procedure TCustomer.SetContactFirst(const Value: String);
+begin
+ FContactFirst := Value;
+end;
+
+procedure TCustomer.SetContactLast(const Value: String);
+begin
+ FContactLast := Value;
+end;
+
+procedure TCustomer.SetName(const Value: String);
+begin
+ FName := Value;
+end;
+
+end.
diff --git a/samples/renders/BusinessObjectsU.pas b/samples/renders/BusinessObjectsU.pas
deleted file mode 100644
index 560d2f25..00000000
--- a/samples/renders/BusinessObjectsU.pas
+++ /dev/null
@@ -1,47 +0,0 @@
-unit BusinessObjectsU;
-
-interface
-
-type
- TPerson = class
- private
- FLastName: String;
- FDOB: TDate;
- FFirstName: String;
- FMarried: boolean;
- procedure SetDOB(const Value: TDate);
- procedure SetFirstName(const Value: String);
- procedure SetLastName(const Value: String);
- procedure SetMarried(const Value: boolean);
- public
- property FirstName: String read FFirstName write SetFirstName;
- property LastName: String read FLastName write SetLastName;
- property DOB: TDate read FDOB write SetDOB;
- property Married: boolean read FMarried write SetMarried;
- end;
-
-implementation
-
-{ TPerson }
-
-procedure TPerson.SetDOB(const Value: TDate);
-begin
- FDOB := Value;
-end;
-
-procedure TPerson.SetFirstName(const Value: String);
-begin
- FFirstName := Value;
-end;
-
-procedure TPerson.SetLastName(const Value: String);
-begin
- FLastName := Value;
-end;
-
-procedure TPerson.SetMarried(const Value: boolean);
-begin
- FMarried := Value;
-end;
-
-end.
diff --git a/samples/renders/RenderSampleControllerU.pas b/samples/renders/RenderSampleControllerU.pas
index 6cda8346..1caaf6b1 100644
--- a/samples/renders/RenderSampleControllerU.pas
+++ b/samples/renders/RenderSampleControllerU.pas
@@ -16,9 +16,9 @@ type
procedure GetCustomers(CTX: TWebContext);
[MVCHTTPMethod([httpGet])]
- [MVCPath('/customers')]
- [MVCProduces('text/xml')]
- procedure GetCustomersXML(CTX: TWebContext);
+ [MVCPath('/customers/($id)')]
+ [MVCProduces('application/json')]
+ procedure GetCustomerByID(CTX: TWebContext);
end;
@@ -29,6 +29,25 @@ uses
{ TRoutingSampleController }
+procedure TRenderSampleController.GetCustomerByID(CTX: TWebContext);
+var
+ Cust: TCustomer;
+begin
+ if CTX.Request.ParamsAsInteger['id'] = 7 then
+ Render(404, 'Customer Not Found')
+ else
+ begin
+ Cust := TCustomer.Create;
+ Cust.Name := 'Daniele Teti Inc.';
+ Cust.ContactFirst := 'Daniele';
+ Cust.ContactLast := 'Teti';
+ Cust.AddressLine1 := 'Rome Street 12';
+ Cust.AddressLine2 := '00100';
+ Cust.City := 'ROME';
+ Render(Cust);
+ end;
+end;
+
procedure TRenderSampleController.GetCustomers(CTX: TWebContext);
var
wm: TWebModule1;
@@ -38,13 +57,4 @@ begin
Render(wm.qryCustomers);
end;
-procedure TRenderSampleController.GetCustomersXML(CTX: TWebContext);
-var
- wm: TWebModule1;
-begin
- wm := GetCurrentWebModule as TWebModule1;
- wm.qryCustomers.Open;
- Render(wm.qryCustomers);
-end;
-
end.
diff --git a/samples/renders/WebModuleU.dfm b/samples/renders/WebModuleU.dfm
index e208d463..6aff3832 100644
--- a/samples/renders/WebModuleU.dfm
+++ b/samples/renders/WebModuleU.dfm
@@ -13,7 +13,6 @@ object WebModule1: TWebModule1
'Password=masterkey'
'DriverID=IB')
ConnectedStoredUsage = [auDesignTime]
- Connected = True
LoginPrompt = False
Left = 160
Top = 40
diff --git a/samples/renders/renders.dpr b/samples/renders/renders.dpr
index 6dcaf932..ed221bac 100644
--- a/samples/renders/renders.dpr
+++ b/samples/renders/renders.dpr
@@ -8,9 +8,9 @@ uses
IdHTTPWebBrokerBridge,
Web.WebReq,
Web.WebBroker,
- WebModuleU in 'WebModuleU.pas' {WebModule1: TWebModule} ,
+ WebModuleU in 'WebModuleU.pas' {WebModule1: TWebModule},
RenderSampleControllerU in 'RenderSampleControllerU.pas',
- BusinessObjectsU in 'BusinessObjectsU.pas';
+ BusinessObjectsU in '..\commons\BusinessObjectsU.pas';
{$R *.res}
diff --git a/samples/renders/renders.dproj b/samples/renders/renders.dproj
index 041250e0..6703c7c0 100644
--- a/samples/renders/renders.dproj
+++ b/samples/renders/renders.dproj
@@ -90,7 +90,7 @@
TWebModule
-
+
Cfg_2
Base
diff --git a/sources/ObjectsMappers.pas b/sources/ObjectsMappers.pas
index 998137dd..01542500 100644
--- a/sources/ObjectsMappers.pas
+++ b/sources/ObjectsMappers.pas
@@ -27,12 +27,7 @@ uses
Generics.Collections,
DBXJSON,
SqlExpr,
- DuckListU,
-
- Xml.xmldom,
- Xml.XMLIntf,
- Xml.XMLDoc
- ;
+ DuckListU;
type
Mapper = class
@@ -89,10 +84,10 @@ type
AReaderInstanceOwner: boolean = True);
class procedure DataSetToJSONArray(ADataSet: TDataSet; AJSONArray: TJSONArray;
ADataSetInstanceOwner: boolean = True);
-// class procedure DataSetRowToXML(ADataSet: TDataSet; Row: IXMLNode;
-// ADataSetInstanceOwner: boolean = True);
-// class procedure DataSetToXML(ADataSet: TDataSet; XMLDocument: String;
-// ADataSetInstanceOwner: boolean = True);
+ // class procedure DataSetRowToXML(ADataSet: TDataSet; Row: IXMLNode;
+ // ADataSetInstanceOwner: boolean = True);
+ // class procedure DataSetToXML(ADataSet: TDataSet; XMLDocument: String;
+ // ADataSetInstanceOwner: boolean = True);
class function ObjectListToJSONArray(AList: TObjectList;
AOwnsInstance: boolean = false): TJSONArray;
class function ObjectListToJSONArrayOfJSONArray(AList: TObjectList)
@@ -609,6 +604,10 @@ begin
if DoNotSerializeThis then
Continue;
end;
+
+ if HasAttribute(_property) then
+ Continue;
+
case _property.PropertyType.TypeKind of
tkInteger, tkInt64:
JSONObject.AddPair(f, TJSONNumber.Create(_property.GetValue(AObject).AsInteger));
@@ -1430,97 +1429,97 @@ begin
if ACloseDataSetAfterScroll then
ADataSet.Close;
end;
-
-//class procedure Mapper.DataSetToXML(ADataSet: TDataSet;
-// XMLDocument: String; ADataSetInstanceOwner: boolean);
-//var
-// Xml: IXMLDocument;
-// Row: IDOMElement;
-//begin
-// DefaultDOMVendor := 'ADOM XML v4';
-// Xml := NewXMLDocument();
-// Xml.Active := True;
-// while not ADataSet.Eof do
-// begin
-// Row := Xml.DOMDocument.createElement('row');
-// // Row := Xml.DocumentElement.AddChild('row');
-// // DataSetRowToXML(ADataSet, Row, false);
-// Xml.DOMDocument.appendChild(Row);
-// ADataSet.Next;
-// end;
-// if ADataSetInstanceOwner then
-// FreeAndNil(ADataSet);
-// Xml.SaveToXML(XMLDocument);
-//end;
//
-//class procedure Mapper.DataSetRowToXML(ADataSet: TDataSet;
-// Row: IXMLNode; ADataSetInstanceOwner: boolean);
-//var
-// I: Integer;
-// key: string;
-// dt: TDateTime;
-// tt: TTime;
-// Time: TTimeStamp;
-// ts: TSQLTimeStamp;
-//begin
-// for I := 0 to ADataSet.FieldCount - 1 do
-// begin
-// key := LowerCase(ADataSet.Fields[I].FieldName);
-// case ADataSet.Fields[I].DataType of
-// TFieldType.ftInteger, TFieldType.ftSmallint, TFieldType.ftShortint:
-// Row.Attributes[key] := ADataSet.Fields[I].AsInteger;
-// // AJSONObject.AddPair(key, TJSONNumber.Create(ADataSet.Fields[I].AsInteger));
-// TFieldType.ftLargeint:
-// begin
-// Row.Attributes[key] := ADataSet.Fields[I].AsLargeInt;
-// end;
-// TFieldType.ftSingle, TFieldType.ftFloat:
-// Row.Attributes[key] := ADataSet.Fields[I].AsFloat;
-// ftString, ftWideString, ftMemo:
-// Row.Attributes[key] := ADataSet.Fields[I].AsWideString;
-// TFieldType.ftDate:
-// begin
-// if not ADataSet.Fields[I].IsNull then
-// begin
-// Row.Attributes[key] := ISODateToString(ADataSet.Fields[I].AsDateTime);
-// end
-// end;
-// TFieldType.ftDateTime:
-// begin
-// if not ADataSet.Fields[I].IsNull then
-// begin
-// Row.Attributes[key] := ISODateTimeToString(ADataSet.Fields[I].AsDateTime);
-// end
-// end;
-// TFieldType.ftTimeStamp:
-// begin
-// if not ADataSet.Fields[I].IsNull then
-// begin
-// ts := ADataSet.Fields[I].AsSQLTimeStamp;
-// Row.Attributes[key] := SQLTimeStampToStr('hh:nn:ss', ts);
-// end
-// end;
-// TFieldType.ftCurrency:
-// begin
-// if not ADataSet.Fields[I].IsNull then
-// begin
-// Row.Attributes[key] := FormatCurr('0.00##', ADataSet.Fields[I].AsCurrency);
-// end
-// end;
-// TFieldType.ftFMTBcd:
-// begin
-// if not ADataSet.Fields[I].IsNull then
-// begin
-// Row.Attributes[key] := BcdToDouble(ADataSet.Fields[I].AsBcd);
-// end
-// end
-// else
-// raise Exception.Create('Cannot find type for field ' + key);
-// end;
-// end;
-// if ADataSetInstanceOwner then
-// FreeAndNil(ADataSet);
-//end;
+// class procedure Mapper.DataSetToXML(ADataSet: TDataSet;
+// XMLDocument: String; ADataSetInstanceOwner: boolean);
+// var
+// Xml: IXMLDocument;
+// Row: IXMLNode;
+// begin
+// DefaultDOMVendor := 'ADOM XML v4';
+// Xml := NewXMLDocument();
+// while not ADataSet.Eof do
+// begin
+// Row := Xml.CreateNode('row');
+// // Row := Xml.DocumentElement.AddChild('row');
+// // DataSetRowToXML(ADataSet, Row, false);
+// Xml.ChildNodes.Add(Row);
+// break;
+// ADataSet.Next;
+// end;
+// if ADataSetInstanceOwner then
+// FreeAndNil(ADataSet);
+// Xml.SaveToXML(XMLDocument);
+// end;
+//
+// class procedure Mapper.DataSetRowToXML(ADataSet: TDataSet;
+// Row: IXMLNode; ADataSetInstanceOwner: boolean);
+// var
+// I: Integer;
+// key: string;
+// dt: TDateTime;
+// tt: TTime;
+// Time: TTimeStamp;
+// ts: TSQLTimeStamp;
+// begin
+// for I := 0 to ADataSet.FieldCount - 1 do
+// begin
+// key := LowerCase(ADataSet.Fields[I].FieldName);
+// case ADataSet.Fields[I].DataType of
+// TFieldType.ftInteger, TFieldType.ftSmallint, TFieldType.ftShortint:
+// Row.Attributes[key] := ADataSet.Fields[I].AsInteger;
+// // AJSONObject.AddPair(key, TJSONNumber.Create(ADataSet.Fields[I].AsInteger));
+// TFieldType.ftLargeint:
+// begin
+// Row.Attributes[key] := ADataSet.Fields[I].AsLargeInt;
+// end;
+// TFieldType.ftSingle, TFieldType.ftFloat:
+// Row.Attributes[key] := ADataSet.Fields[I].AsFloat;
+// ftString, ftWideString, ftMemo:
+// Row.Attributes[key] := ADataSet.Fields[I].AsWideString;
+// TFieldType.ftDate:
+// begin
+// if not ADataSet.Fields[I].IsNull then
+// begin
+// Row.Attributes[key] := ISODateToString(ADataSet.Fields[I].AsDateTime);
+// end
+// end;
+// TFieldType.ftDateTime:
+// begin
+// if not ADataSet.Fields[I].IsNull then
+// begin
+// Row.Attributes[key] := ISODateTimeToString(ADataSet.Fields[I].AsDateTime);
+// end
+// end;
+// TFieldType.ftTimeStamp:
+// begin
+// if not ADataSet.Fields[I].IsNull then
+// begin
+// ts := ADataSet.Fields[I].AsSQLTimeStamp;
+// Row.Attributes[key] := SQLTimeStampToStr('hh:nn:ss', ts);
+// end
+// end;
+// TFieldType.ftCurrency:
+// begin
+// if not ADataSet.Fields[I].IsNull then
+// begin
+// Row.Attributes[key] := FormatCurr('0.00##', ADataSet.Fields[I].AsCurrency);
+// end
+// end;
+// TFieldType.ftFMTBcd:
+// begin
+// if not ADataSet.Fields[I].IsNull then
+// begin
+// Row.Attributes[key] := BcdToDouble(ADataSet.Fields[I].AsBcd);
+// end
+// end
+// else
+// raise Exception.Create('Cannot find type for field ' + key);
+// end;
+// end;
+// if ADataSetInstanceOwner then
+// FreeAndNil(ADataSet);
+// end;
class function Mapper.InternalExecuteSQLQuery(AQuery: TSQLQuery; AObject: TObject;
WithResult: boolean): Int64;