#1 Yesterday 15:50:35

mrbar2000
Member
From: Brazil
Registered: 2016-10-26
Posts: 113

Automap ToA with TNullxxx "invalid variant type" (just on linux)

  TUsuario = class(TAuthUser)
  private
    FTipo: TTipoUsuario;
    FEmpresaID: TID;
    FIdExterno: TNullableInteger;
  published
    property Tipo: TTipoUsuario read FTipo write FTipo;
    property EmpresaID: TID read FEmpresaID write FEmpresaID;
    property IdExterno: TNullableInteger read FIdExterno write FIdExterno;
  end;    

  TDTOUsuario = packed record
    ID: Int64;
    IdExterno: TNullableInteger;
    Email: RawUtf8;
    Nome: RawUtf8;
    Cpf: RawUtf8;
  end;  

function InitMap_Usuario: TRttiMap;
begin
  Result.Init(TUsuario, TypeInfo(TDTOUsuario)).AutoMap
    .Map([
      'DisplayName', 'Nome',
      'LogonName', 'Email'
  ]);
end;

procedure ToObject(const pDTOUsuario: TDTOUsuario; pObj: TUsuario);
begin
  InitMap_Usuario.ToA(pObj, @pDTOUsuario);
end;

function ToObject(const pDTOUsuario: TDTOUsuario): TUsuario;
begin
  Result := nil;
  InitMap_Usuario.ToA(Result, @pDTOUsuario);  <<<< invalid variant type when 
end;

function ToDTO(pUsuario: TUsuario): TDTOUsuario;
begin
  InitMap_Usuario.ToB(pUsuario, @Result);
end;   
...
procedure RegisterDTOs;
const
  ...
  cRegDTOUsuario = 'ID Int64 IdExterno variant Email,Nome,Cpf RawUtf8';
begin
  TJsonSerializer.RegisterCustomJSONSerializerFromText(TypeInfo(TDTOUsuario), cRegDTOUsuario);
end;

initialization
  RegisterDTOs;

debugging we see that erro happen in "procedure TRttiMap.ToA(A, B: pointer);"

...
    if pa^ <> nil then
    begin
      writeln('ToA: '+pa^.Name);
      Flush(Output);

      pb^.CopyValue(A, B, pa^); // invalid variant type on linux here when (pa^.Name = 'IdExterno') (windows works)

      writeln('After ToA: '+pa^.Name);
      Flush(Output);
    end;

Offline

#2 Yesterday 16:57:41

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,367
Website

Re: Automap ToA with TNullxxx "invalid variant type" (just on linux)

For which actual value in the field?

Offline

#3 Yesterday 19:11:59

mrbar2000
Member
From: Brazil
Registered: 2016-10-26
Posts: 113

Re: Automap ToA with TNullxxx "invalid variant type" (just on linux)

sorry. To field:
     FIdExterno: TNullableInteger;

Offline

#4 Yesterday 19:37:10

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,367
Website

Re: Automap ToA with TNullxxx "invalid variant type" (just on linux)

Field VALUE please.

Offline

#5 Yesterday 19:54:47

mrbar2000
Member
From: Brazil
Registered: 2016-10-26
Posts: 113

Re: Automap ToA with TNullxxx "invalid variant type" (just on linux)

{..., "IdExterno": 0, ...} if put other value i get same error
sample
{..., "IdExterno": 15, ...}

Last edited by mrbar2000 (Yesterday 19:55:21)

Offline

#6 Today 13:33:58

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,367
Website

Re: Automap ToA with TNullxxx "invalid variant type" (just on linux)

Why do you put Result := nil; before ToA(Result, @pDTOUsuario) in ToObject ?
You need to allocate something to copy to, I guess.

There was a problem which should be fixed with
https://github.com/synopse/mORMot2/commit/331307440

Offline

Board footer

Powered by FluxBB