#1 2026-04-29 08:49:27

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 603

Question concering RecordLoadJSON

Ist it possible to use a different "JSONName" for a record property ?

Here is a sample how it could be done ?!

  TBaseResponse = record
  public
    [JsonName('@odata.context')]
    odataContext : RawUtf8;
    [JsonName('@odata.metadataEtag')]
    odataMetadataEtag : RawUtf8;

    function FromJSON(const AResponseJSON : RawUtf8) : TresultRec;
    function ToJSON : RawUtf8;
  end;

implementation

{ TBaseResponse }

function TBaseResponse.FromJSON(const AResponseJSON: RawUtf8): TresultRec;
begin
  if Length(AResponseJSON) = 0 then Exit(Result.Fehler('Keine Response erhalten!'));
  try
    RecordLoadJSON(Self, AResponseJSON, TypeInfo(TBaseResponse));
  except
    on e : Exception do
      Result.Exception(e);
  end;
end;

function TBaseResponse.ToJSON: RawUtf8;
begin
  Result := RecordSaveJSON(Self, TypeInfo(TBaseResponse), True);
end;

Any Idea/Thoughts ?


Rad Studio 12.3 Athens / 13.0 Ganymede

Offline

#2 2026-04-29 09:00:48

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 603

Re: Question concering RecordLoadJSON

Actually we use a Stringreplace before and after


Rad Studio 12.3 Athens / 13.0 Ganymede

Offline

#3 2026-04-29 09:44:10

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

Re: Question concering RecordLoadJSON

You have TRttiCustomProps.NameChange() for that, or you could use text-based RTTI.

Offline

#4 2026-04-29 09:45:03

malom
Member
Registered: 2017-01-12
Posts: 5

Re: Question concering RecordLoadJSON

Perhaps Rtti.RegisterFromText() can be used for this.

Offline

Board footer

Powered by FluxBB