pult / SuperObject.Delphi

Pascal (Delphi, FPC) json parser library SuperObject
The Unlicense
45 stars 22 forks source link

Marshalling error on restoring object from json #6

Closed vfisher closed 10 months ago

vfisher commented 10 months ago

On old versions of superobject this code is working ok. With modern version from this repo it fails with "Marshalling error". Code to reproduce bug:

program sobug;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  superobject;

const
  s: String =
'{' +
'    "request_id": "47f314cc-4279-4ee7-bf47-df4256be124c"' +
'    ,"result": {' +
'        "class_id": "ef9a343f-1c8d-4c9f-864b-4bce79ca4075",' +
'        "code": 2036,' +
'        "human_readable_message": "",' +
'        "message": "Error",' +
'        "res": "TRANSACTION_IMPOSSIBLE_TYPE_ID_FOR_RETURN"' +
'    }' +
'}';

Type
  TCustomResponseModel = Class Abstract
  End;

  TResponseResult = Class
  Public
    res: String;
    code: Int64;
    message: String;
    humanReadableMessage: String;
  End;

  TCardLabResponse = Class(TCustomResponseModel)
  Public
    result: TResponseResult;
  End;

  TTransactionItem = Record
  Private
    mode: String;
    on_device_id: String;
    create_ts: Int64;
    state: String;
  Public
    id: TGUID;
    ext_id: Int64;
    ids: TArray<String>;
    coupons_for_print: TArray<String>;
  End;

  TCustomTransactionRs = Class(TCardLabResponse)
  Public
    data: TTransactionItem;
  End;

var
  obj: TCustomTransactionRs;
  ACTX: TSuperRttiContext;
begin
  try
    ACTX:= TSuperRttiContext.Create;
    try
      obj:= ACTX.AsType<TCustomTransactionRs>(SO(s));
    finally
      ACTX.Free;
    end;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
pult commented 10 months ago

fixed https://github.com/pult/SuperObject.Delphi/commit/d28b5a825ffe83144f310fa3aade048585fb44f3 your sample: https://github.com/pult/SuperObject.Delphi/blob/master/Demos/issues/so_issue_6.dpr