Hi! i need some help with XE7 :)

Hi! i need some help with XE7 :)

i'm triing to use parse to store and read a simple object , like a tdocument, something like this:

 trow = class
     code : string ;
     description : string ;
 end;

 trows =  TobjectList;

 tdoc = class
       someinfo: string ;
       etc etc  : tdate ;
       rows : trows;
  end;


i can easily mashall it , with "tjson.ObjectToJsonObject(doc)" but i can't unmarshall it ...
with tjson.JsonToObject(ajson)  it not raise exception but not convert..

so i tried to create a manual marshal for Rows in document, and i have same problem.  can marshall witout problem, but in unmarshalling procedure i don't have data object initialized so i have a access violation.....
there's some "initialization" procedure to call before?
thanks

Comments

  1. How have you registered converter for  trows class and rows field?

    ReplyDelete
  2. You need manually write code:
     rows := trows.Create;

    NOT in constructor, but where you UNMARSHAL your object.

    Like this:

    class function TmsSerializeController.DeSerialize(const aFileName: string)
      : TmsDiagramm;
    var
      l_UnMarshal: TJSONUnMarshal;
      l_StringList: TStringList;
    begin
      try
        l_UnMarshal := TJSONUnMarshal.Create;

        l_UnMarshal.RegisterReverter(TmsDiagramm, 'FShapeList',
          procedure(Data: TObject; Field: String; Args: TListOfObjects)
          var
            l_Object: TObject;
            l_Diagramm: TmsDiagramm;
            l_msShape: TmsShape;
          begin
            l_Diagramm := TmsDiagramm(Data);
            l_Diagramm.ShapeList := TmsShapeList.Create;
            assert(l_Diagramm <> nil);

            for l_Object in Args do
            begin
              l_msShape := l_Object as TmsShape;
              l_Diagramm.ShapeList.Add(l_msShape);
            end
          end);

    FShapeList => rows

    ReplyDelete
  3. Thanks, i'll try! In my test i have problem with Args too. It was nil :(

    ReplyDelete
  4. l_Marshal.RegisterConverter(TmsShapeContainer, 'fList',
          function(Data: TObject; Field: string): TListOfObjects
          var l_Shape : TmsShape;
              l_Index: integer;
          begin
            SetLength(Result, (Data As TmsShapeContainer).fList.Count);
            l_Index := 0;
            for l_Shape in (Data As TmsShapeContainer).fList do
            begin
              Result[l_Index] := l_Shape;
              Inc(l_Index);
            end;
          end
          );

    ReplyDelete
  5. l_Marshal.RegisterConverter(TmsDiagramm, 'FShapeList',
          function(Data: TObject; Field: string): TListOfObjects
          var
            l_Shape: ImsShape;
            l_Index: Integer;
          begin
            assert(Field = 'FShapeList');
            SetLength(Result, (Data As TmsDiagramm).ShapeList.Count);
            l_Index := 0;
            for l_Shape in (Data As TmsDiagramm).ShapeList do
            begin
              Result[l_Index] := l_Shape.HackInstance;
              Inc(l_Index);
            end; // for l_Shape
          end);

    ReplyDelete
  6. l_UnMarshal.RegisterReverter(TmsDiagramm, 'FShapeList',
          procedure(Data: TObject; Field: String; Args: TListOfObjects)
          var
            l_Object: TObject;
            l_Diagramm: TmsDiagramm;
            l_msShape: TmsShape;
          begin
            l_Diagramm := TmsDiagramm(Data);
            l_Diagramm.ShapeList := TmsShapeList.Create;
            assert(l_Diagramm <> nil);
     
            for l_Object in Args do
            begin
              l_msShape := l_Object as TmsShape;
              l_Diagramm.ShapeList.Add(l_msShape);
            end
          end);

    ReplyDelete
  7. TmsDiagramm == tdoc 
    FShapeList == rows 
    TmsShape == trows

    Have you got the clue idea?

    Maybe you send ve your code and I'll try ti fix it?

    ReplyDelete
  8. Hi! I tried but in reverter procs Args paramter is always nil :(  i suppose there's some difference between xe6 and xe7...  TJSONUnMarshal.unmarshall not exists. there's a CreateObject method instead .... 
    can i attach my test project?

    ReplyDelete
  9. o my god, i found the problem .... i used tJsonmarshall/ unmarshall of REST.JSONREFLECT unit ....... i MUST use data.dbxjsonreflect ....... Marco Cantù why not change method name? :)

    ReplyDelete

Post a Comment