Git Product home page Git Product logo

delphi-jsontodelphiclass's People

Contributors

pkgeorgiev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

delphi-jsontodelphiclass's Issues

Ampersand for "label"

I use the generator on the site.

When generating a field with the name "label", an ampersand is necessary like with the field "type".

Problem with "Nested Arrays"

I use the generator on the site.

What is the reason for the lack of support for nested arrays?
Personally, I solve it in the way below:

TVkKeyboardButtons = TArray<TVkKeyboardButton>; -- **and array there**

TVkKeyboard = class
  private
    FButtons: TArray<TVkKeyboardButtons>;
    FOne_time: Boolean;
  public
    property buttons: TArray<TVkKeyboardButtons> read FButtons write FButtons; - **array there**
    property one_time: Boolean read FOne_time write FOne_time;
    destructor Destroy; override;
    function ToJsonString: string;
    class function FromJsonString(AJsonString: string): TVkKeyboard;
  end;

Save Code is missing in uSaveUnitForm.pas

So I added some save code:

procedure TSaveUnitForm.btnSaveClick(Sender: TObject);
begin
if SaveDialog1.Execute then
begin
Memo1.Lines.SaveToFile(SaveDialog1.FileName);
end;
end;

I change sd to SaveDialog1. Change it back if you just want to plug and play or use the code below :)

So then this code would look like:

if sd.Execute then
begin
Memo1.Lines.SaveToFile(sd.FileName);
end;

Bye,
Skybuck.

Json Output and Arrays

Nice work :-)

I am not sure if its your original or the branch done by JensBorrisholt that is causing me issues however.

I create the master and put the content in, but if I then try to turn the content back to JSON it crashes with exceptions.
The issues appears to be where certain object arrays dont have any content?

The unit it created is below..
``
unit mchimp;

interface

uses
Pkg.Json.DTO, System.Generics.Collections, REST.Json.Types;

{$M+}

type
TLinksDTO_001 = class
private
FHref: string;
FMethod: string;
FRel: string;
FSchema: string;
FTargetSchema: string;
published
property Href: string read FHref write FHref;
property Method: string read FMethod write FMethod;
property Rel: string read FRel write FRel;
property Schema: string read FSchema write FSchema;
property TargetSchema: string read FTargetSchema write FTargetSchema;
end;

TLinksDTO = class
private
FHref: string;
FMethod: string;
FRel: string;
FTargetSchema: string;
published
property Href: string read FHref write FHref;
property Method: string read FMethod write FMethod;
property Rel: string read FRel write FRel;
property TargetSchema: string read FTargetSchema write FTargetSchema;
end;

TTagsDTO = class
private
FId: Integer;
FName: string;
published
property Id: Integer read FId write FId;
property Name: string read FName write FName;
end;

TLocationDTO = class
private
FCountry_Code: string;
FDstoff: Integer;
FGmtoff: Integer;
FLatitude: Integer;
FLongitude: Integer;
FTimezone: string;
published
property Country_Code: string read FCountry_Code write FCountry_Code;
property Dstoff: Integer read FDstoff write FDstoff;
property Gmtoff: Integer read FGmtoff write FGmtoff;
property Latitude: Integer read FLatitude write FLatitude;
property Longitude: Integer read FLongitude write FLongitude;
property Timezone: string read FTimezone write FTimezone;
end;

TStatsDTO = class
private
FAvg_Click_Rate: Integer;
FAvg_Open_Rate: Integer;
published
property Avg_Click_Rate: Integer read FAvg_Click_Rate write FAvg_Click_Rate;
property Avg_Open_Rate: Integer read FAvg_Open_Rate write FAvg_Open_Rate;
end;

TMerge_FieldsDTO = class
private
FADDRESS: string;
FBIRTHDAY: string;
FFNAME: string;
FLNAME: string;
FMMERGE6: string;
FPHONE: string;
published
property ADDRESS: string read FADDRESS write FADDRESS;
property BIRTHDAY: string read FBIRTHDAY write FBIRTHDAY;
property FNAME: string read FFNAME write FFNAME;
property LNAME: string read FLNAME write FLNAME;
property MMERGE6: string read FMMERGE6 write FMMERGE6;
property PHONE: string read FPHONE write FPHONE;
end;

TMembersDTO = class
private
FEmail_Address: string;
FEmail_Client: string;
FEmail_Type: string;
FId: string;
FIp_Opt: string;
FIp_Signup: string;
FLanguage: string;
FLast_Changed: string;
[JSONName('_links')]
FLinksArray: TArray;
[GenericListReflect]
FLinks: TObjectList;
FList_Id: string;
FLocation: TLocationDTO;
FMember_Rating: Integer;
FMerge_Fields: TMerge_FieldsDTO;
FSource: string;
FStats: TStatsDTO;
FStatus: string;
[JSONName('tags')]
FTagsArray: TArray;
[GenericListReflect]
FTags: TObjectList;
FTags_Count: Integer;
FTimestamp_Opt: string;
FTimestamp_Signup: string;
FUnique_Email_Id: string;
FVip: Boolean;
FWeb_Id: Integer;
function GetTags: TObjectList;
function GetLinks: TObjectList;
published
property Email_Address: string read FEmail_Address write FEmail_Address;
property Email_Client: string read FEmail_Client write FEmail_Client;
property Email_Type: string read FEmail_Type write FEmail_Type;
property Id: string read FId write FId;
property Ip_Opt: string read FIp_Opt write FIp_Opt;
property Ip_Signup: string read FIp_Signup write FIp_Signup;
property Language: string read FLanguage write FLanguage;
property Last_Changed: string read FLast_Changed write FLast_Changed;
property Links: TObjectList read GetLinks;
property List_Id: string read FList_Id write FList_Id;
property Location: TLocationDTO read FLocation write FLocation;
property Member_Rating: Integer read FMember_Rating write FMember_Rating;
property Merge_Fields: TMerge_FieldsDTO read FMerge_Fields write FMerge_Fields;
property Source: string read FSource write FSource;
property Stats: TStatsDTO read FStats write FStats;
property Status: string read FStatus write FStatus;
property Tags: TObjectList read GetTags;
property Tags_Count: Integer read FTags_Count write FTags_Count;
property Timestamp_Opt: string read FTimestamp_Opt write FTimestamp_Opt;
property Timestamp_Signup: string read FTimestamp_Signup write FTimestamp_Signup;
property Unique_Email_Id: string read FUnique_Email_Id write FUnique_Email_Id;
property Vip: Boolean read FVip write FVip;
property Web_Id: Integer read FWeb_Id write FWeb_Id;
public
constructor Create;
destructor Destroy; override;
end;

TRootDTO = class(TJsonDTO)
private
[JSONName('_links')]
FLinksArray: TArray<TLinksDTO_001>; (* TLinksDTO_001 )
[GenericListReflect]
FLinks: TObjectList<TLinksDTO_001>; (
TLinksDTO_001 )
FList_Id: string;
[JSONName('members')]
FMembersArray: TArray;
[GenericListReflect]
FMembers: TObjectList;
FTotal_Items: Integer;
function GetMembers: TObjectList;
function GetLinks: TObjectList<TLinksDTO_001>; (
TLinksDTO_001 )
published
property Links: TObjectList<TLinksDTO_001> read GetLinks; (
TLinksDTO_001 *)
property List_Id: string read FList_Id write FList_Id;
property Members: TObjectList read GetMembers;
property Total_Items: Integer read FTotal_Items write FTotal_Items;
destructor Destroy; override;
end;

implementation

{ TMembersDTO }

constructor TMembersDTO.Create;
begin
inherited;
FMerge_Fields := TMerge_FieldsDTO.Create;
FStats := TStatsDTO.Create;
FLocation := TLocationDTO.Create;
end;

destructor TMembersDTO.Destroy;
begin
FMerge_Fields.Free;
FStats.Free;
FLocation.Free;
GetTags.Free;
GetLinks.Free;
inherited;
end;

function TMembersDTO.GetTags: TObjectList;
begin
if not Assigned(FTags) then
begin
FTags := TObjectList.Create;
FTags.AddRange(FTagsArray);
end;
Result := FTags;
end;

function TMembersDTO.GetLinks: TObjectList;
begin
if not Assigned(FLinks) then
begin
FLinks := TObjectList.Create;
FLinks.AddRange(FLinksArray);
end;
Result := FLinks;
end;

{ TRootDTO }

destructor TRootDTO.Destroy;
begin
GetMembers.Free;
GetLinks.Free;
inherited;
end;

function TRootDTO.GetMembers: TObjectList;
begin
if not Assigned(FMembers) then
begin
FMembers := TObjectList.Create;
FMembers.AddRange(FMembersArray);
end;
Result := FMembers;
end;

function TRootDTO.GetLinks: TObjectList<TLinksDTO_001>; (* TLinksDTO_001 )
begin
if not Assigned(FLinks) then
begin
FLinks := TObjectList<TLinksDTO_001>.Create; (
TLinksDTO_001 *)
FLinks.AddRange(FLinksArray);
end;
Result := FLinks;
end;

end.
``
Test Code

``
var
response_string:string;
MC: TRootDTO;

tg:extended;
tgn:integer;
diag:system.Text;
tag:TTagsDTO;
linkbase:TLinksDTO_001;
linkmc:TLinksDTO;

begin
restrequest1.Params[0].value:='0';
restrequest1.Params[1].Value:='1';
restrequest1.Params[2].Destroy;
RestRequest1.Execute;
response_string:=RestResponse1.Content;
assignfile(diag,'c:\owlbarn\mchimpupdate.json');
rewrite(diag);
writeln(diag,response_string);
writeln(diag,'{ EMPTY PAD }');

MC:=TRootDTO.Create;
linkbase:=TlinksDTO_001.Create;
linkbase.href:=' ';
linkbase.Method:=' ';
linkbase.Rel:=' ';
linkbase.Schema:=' ';
linkbase.TargetSchema:=' '; *)
MC.AsJson:=response_string;
MC.Members[0].Links.create(false);
linkmc:=TLinksDTO.Create;
linkmc.Href:='';
linkmc.Method:='';

tag:=TTagsDTO.Create;
tag.Id:=123456;
tag.Name:='12121212112';
mc.Members[0].Tags.create(false);
mc.Links.Create(false);
mc.links.Add(linkbase);
mc.Members[0].Tags.add(tag);
mc.Members[0].Links.add(linkmc);

response_string:=MC.asjson;
writeln(diag,response_string);
closefile(diag);
tag.Destroy;
MC.destroy;
linkbase.Destroy;
linkmc.Destroy;
showmessage('done');

end;
``
So as long as create the Link classes and put dummy content in it all works, but otherwise it fails.

I am try to add the tags object array which works but creates a duplicate entry in the JSON

"tags": [],
"tags": [
{
"id": 123456,
"name": "12121212112"
}
],

If you cannot help please say so and just close the issue.

I dont seem to be able to raise any issue with Jens.

Thanks in advance
Phil

Object can't be converted from Json array

This is demo generated TRootClass:

TRootClass = class
private
  FItems: TArray<TItemClass>;
public
  property Items: TArray<TItemClass> read FItems write FItems;
  destructor Destroy; override;
  function ToJsonString: string;
  class function FromJsonString(AJsonString: string): TRootClass;
end;

When calling TRootClass.FromJsonString, it will throw exception.

Generate Class from JSON with array as root

Hi Petar,

What a great tool!!!

Could you verify the following behavior. The tool does not seem to be able to cope with a JSON string with an array as root (jsonlint reports the string to be valid JSON):

    [
    {
      "Id":"9165d168-c6de-4eea-b280-1fc147576199",
      "Description":"Your Advice",
      "Code":"NL_YR_ADV"
    },
    {
      "Id":"d03a1dbf-5b3f-4dd4-ba07-0ffd3b67ca6f",
      "Description":"Your Garden Products",
      "Code":"NL_YR_GRD"
    }
  ]

The tool still generates a correct ItemClass, but the TRootClass.FromJsonString assumes the JSON "root" to be an object, which in the end (when using calling TRootClass.FromJsonString) generates an error "input value is not a valid Object" and/or Access Violation, because in this case the "root" is an array.

Please, could you ...

  1. explain whether this is by design
  2. change the tool so it will generate a correct TRootClass.FromJsonString
  3. tell me what would be the most decent work around, if it cannot be changed in the tool.

Regards,
Erik

Problem with GetAsJson and RefreshArray

Ao gerar minha classe, obtenho os erros:

  • [dcc32 Error] UPedido.pas(34): E2137 Method 'GetAsJson' not found in base class

  • [dcc32 Error] UPedido.pas(60): E2003 Undeclared identifier: 'RefreshArray'

  • Classe Gerada:

unit UPedido;

interface

uses
Pkg.Json.DTO, System.Generics.Collections, REST.Json.Types;

{$M+}

type
TProdutos = class
private
FDescricao: string;
FId: Integer;
FQtde: Integer;
FUnitario: Double;
published
property Descricao: string read FDescricao write FDescricao;
property Id: Integer read FId write FId;
property Qtde: Integer read FQtde write FQtde;
property Unitario: Double read FUnitario write FUnitario;
end;

TPedido = class(TJsonDTO)
private
FCliente: string;
FId: Integer;
[JSONName('produtos'), JSONMarshalled(False)]
FProdutosArray: TArray;
[GenericListReflect]
FProdutos: TObjectList;
function GetProdutos: TObjectList;
protected
function GetAsJson: string; override;
published
property Cliente: string read FCliente write FCliente;
property Id: Integer read FId write FId;
property Produtos: TObjectList read GetProdutos;
public
destructor Destroy; override;
end;

implementation

{ TPedido }

destructor TPedido.Destroy;
begin
GetProdutos.Free;
inherited;
end;

function TPedido.GetProdutos: TObjectList;
begin
Result := ObjectList(FProdutos, FProdutosArray);
end;

function TPedido.GetAsJson: string;
begin
RefreshArray(FProdutos, FProdutosArray);
Result := inherited;
end;

end.

The property ... has unknown type

When the file starts as:

{
"html_attributions": [],
"next_page_token": ...

it shows the message: The property [html_attributions] has unknown type.

Application vanishing while object is loading the JSON file (using AsJSON method)

Hello,

I was able to create my Delphi Plain Objects from a "sample" JSON file.

Now, when working with real data (JSON file is about 2.5Mb) application is vanishing without any error message (same issue when using the JSONToDelphiClass and loading the JSON file).

I understand that this explanation is quite vague but I don't know where to look at. I'll be happy to share the JSON file with you (private).

Kind regards,
Stéphane

FMX Memo is very slow

FMX Memo is very slow for large quantities of text.

Possible solutions could be: VCL version.

Or faster FMX TMemo replacement.

Or possibilities could be processing/parsing and saving directly to file circumventing slow GUI components.

Error parse nested arrays

The system has an error when trying to convert the json below.
Even though he was a valid json, could you help me ?

{ "iTotalRecords":34, "iTotalDisplayRecords":34, "aaData":[ [ 1, 1, 1, "Papel de 5 cm", "Sim", "Não", "Não", " " ], [ 2, 1, 1, "Papel de 6 cm", "Sim", "Não", "Não", " " ], [ 3, 1, 1, "Papel de 7 cm", "Sim", "Não", "Não", " " ], [ 4, 1, 1, "Papel de 8 cm", "Sim", "Não", "Não", " " ], [ 5, 1, 1, "Papel de 9 cm", "Sim", "Não", "Não", " " ], [ 6, 1, 1, "Papel de 10 cm", "Sim", "Não", "Não", " " ], [ 7, 1, 1, "Papel de 11 cm", "Sim", "Não", "Não", " " ], [ 8, 1, 1, "Papel de 12 cm", "Sim", "Não", "Não", " " ], [ 9, 1, 1, "Papel de 15 cm", "Sim", "Não", "Não", " " ], [ 10, 1, 1, "Papel de 17 cm", "Sim", "Não", "Não", " " ], [ 11, 1, 1, "Papel de 20 cm", "Sim", "Não", "Não", " " ], [ 12, 1, 1, "Papel de 25 cm", "Sim", "Não", "Não", " " ], [ 13, 1, 1, "Papel de 30 cm", "Sim", "Não", "Não", " " ], [ 14, 1, 1, "Papel de 35 cm", "Sim", "Não", "Não", " " ], [ 15, 1, 1, "Papel de 40 cm", "Sim", "Não", "Não", " " ], [ 16, 1, 1, "Papel de 45 cm", "Sim", "Não", "Não", " " ], [ 17, 1, 1, "Papel de 50 cm", "Sim", "Não", "Não", " " ], [ 18, 1, 1, "Papel de 60 cm", "Sim", "Não", "Não", " " ], [ 19, 1, 1, "Papel de 13 cm", "Sim", "Não", "Não", " " ], [ 20, 1, 1, "Envelope 12 x 10", "Sim", "Não", "Não", " " ], [ 21, 1, 1, "Envelope 10 x 18", "Sim", "Não", "Não", " " ], [ 22, 1, 1, "Envelope 12 x 15", "Sim", "Não", "Não", " " ], [ 23, 1, 1, "Envelope 12 x 28", "Sim", "Não", "Não", " " ], [ 24, 1, 1, "Envelope 15 x 17", "Sim", "Não", "Não", " " ], [ 25, 1, 1, "Envelope 15 x 29", "Sim", "Não", "Não", " " ], [ 26, 1, 1, "Envelope 20 x 24", "Sim", "Não", "Não", " " ], [ 27, 1, 1, "Envelope 20 x 40", "Sim", "Não", "Não", " " ], [ 28, 1, 1, "Envelope 25 x 27", "Sim", "Não", "Não", " " ], [ 29, 1, 1, "Envelope 25 x 35", "Sim", "Não", "Não", " " ], [ 30, 1, 1, "Envelope 30 x 36", "Sim", "Não", "Não", " " ], [ 32, 1, 1, "SMS PESADO 1200X1200", "Sim", "Não", "Não", " " ], [ 34, 1, 1, "PAPEL GRAU CIRURGICO", "Sim", "Sim", "Sim", " " ], [ 35, 1, 1, "SMS", "Sim", "Sim", "Não", " " ], [ 36, 1, 1, "Tecido", "Sim", "Sim", "Não", " " ] ] }

@HemulGM thankyou for your example I'll fix it in my fork of the project

@JensBorrisholt Can you test this JSON, does it generate an error in the data type of the ID field?

[
{
"id": "01010101",
"descripcion": "No existe en el catálogo",
"incluirIVATrasladado": "Opcional",
"incluirIEPSTrasladado": "Opcional",
"complementoQueDebeIncluir": "",
"fechaInicioVigencia": "07-01-2019",
"fechaFinVigencia": "",
"estimuloFranjaFronteriza": "00",
"palabrasSimilares": "Público en general"
}
]

Two issues

  1. tool can identify date value and makes it TDate type, but after calling FromJSONSTring, the value is 0 while the value in original JSON is “2016-0102”

  2. maps all the numbers to Extended instead of Double

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.