ahausladen / JsonDataObjects

JSON parser for Delphi 2009 and newer
MIT License
413 stars 160 forks source link

Can't generate unit from valid json #59

Closed ptrocewicz closed 4 years ago

ptrocewicz commented 4 years ago

Sample json:

{ "promotions":[ { "id":1, "title":"Special offer", "start_at":"2014-11-01 00:00:00", "finish_at":"2014-11-05 00:00:00", "promotion_type":1, "promotion_value":5000, "promotion_on_type":1, "products":[ 1, 2 ], "promotion_on_value":[ 1, 2 ], "activate":2, "created_at":"2011-09-22 01:15:35" }, { "id":2, "title":"Winter sale", "start_at":"2014-12-01 00:00:00", "finish_at":"2014-12-30 00:00:00", "promotion_type":2, "promotion_value":25, "promotion_on_type":1, "products":[ 1, 2 ], "promotion_on_value":[ 1, 2 ], "activate":2, "created_at":"2011-09-22 01:15:35" } ] }

ahausladen commented 4 years ago

What do you mean by "can't generate unit" ? JsonDataObjects can read that JSON string.

ptrocewicz commented 4 years ago

It crashes on line 556 in Pkg.Json.Mapper (Delphi 10.3.3): Lines.AddFormat(' %s: TObjectList<%s>;', [StubField.FieldName, StubArrayField.FieldClass.Name]);

ahausladen commented 4 years ago

So you are not using my JsonDataObjects unit but reporting a bug in Delphi's own JSON library? Delphi's JSON library uses the same class names, so it could happen that TJsonObject is not from JsonDataObjects but from System.JSON.pas

ahausladen commented 4 years ago

Could it be that you do a hard type cast "TJsonObject(obj)" somewhere but you cast to the wrong TJsonObject class.

ptrocewicz commented 4 years ago

Sorry, my mistake, wrong github repo .