Origin [Jens Borrisholt] (https://github.com/JensBorrisholt/Delphi-JsonToDelphiClass)
Eg this JSON
[
{
"createdAt": null,
"updatedAt": "2013-05-28T15:47:57.962Z",
"username": "jacquelyn88"
}
]
Generates the following DTO:
TItems = class
private
FCreatedAt: string;
[SuppressZero]
FUpdatedAt: TDateTime;
FUsername: string;
published
property CreatedAt: string read FCreatedAt write FCreatedAt;
property UpdatedAt: TDateTime read FUpdatedAt write FUpdatedAt;
property Username: string read FUsername write FUsername;
end;
[SuppressZero]
Delphi doesn't support Nullable types, so use this attribute to strip TDateTime property where value is 0.A Small example:
type
TDateTimeDTO = class(TJsonDTO)
private
[SuppressZero]
FSuppressDate: TDateTime;
FNoSuppressDate: TDateTime;
public
property DateSuppress: TDateTime read FSuppressDate write FSuppressDate;
property NoDateSuppress: TDateTime read FNoSuppressDate write FNoSuppressDate;
end;
The above class will generate the following JSON, if both properties is 0
{
"suppressDate": "",
"noSuppressDate": "1899-12-30T00:00:00.000Z"
}
NOTE: You can turn off this feature in the settings form
E.g this JSON generated faulty code:
{
"/": {
"readonly": true
},
"\\": {
"readonly": true
}
}
Eg this JSON
{
"ArrayTest": [
{
"S1": "5102"
},
{
"S2": "True"
}
]
}
Generates the following DTO:
TArrayTestDTO = class
private
FS1: string;
FS2: string;
published
property S1: string read FS1 write FS1;
property S2: string read FS2 write FS2;
end;
Generates Delphi Classes based on JSON string. Just like XML Data Binding, but for JSON.
Build entirely on the RTL (no external dependencies) so it's cross-platform;
Accepts any valid JSON string, no matter how complex the object is;
Visualizes the structure of the JSON objects in a treeview;
Generates complete delphi unit (declaration and implementation), based on the JSON string input;
Automatically prefixes reserved Delphi words with "&" (ampersand);
Support for JSON string that contains empty Array;
Adds support code to automatically destroy complex sub types. So you don't have to manage subobject's lifetime manually;
Uses TObjectList
Adds helper serialization/deserialization functions;
Serialization and deserialization results in the same JSON structure!
Automatically detects date/datetime parts and maps them to TDate/TDateTime (as long as dates are ISO8601 compliant);
Maps floating point numbers to Double
Maps Number to Integer or Int64 depending on the number
Maps true/false values to Boolean;
Supports JSON pretty print to format the input string;
Simple and responsive GUI;
Automatic check for update, based on ITask (Parallel Programming Library)!
It's open source! You can find the source code and binary releases on GitHub.
If the JSON array is empty the contained type is unknown. Unit generation works only with known and supported types.
*** The releases of JsonToDelphiClass (source and binaries) are public and reside on GitHub. The update unit uses GitHub's REST API to enumerate tags/releases.
Report any problems/suggestions using GitHub's facilities.