- This topic has 1 reply, 2 voices, and was last updated 5 years, 2 months ago by .
Viewing 1 reply thread
Viewing 1 reply thread
- You must be logged in to reply to this topic.
Hi,
I implementing a REST client for an existing REST API which I don’t control. The thing is that the JSON for the REST API uses unnecessary elements for instance:
{ “FiEntryPar”: { “Element”: { “Fields”: { “Year”: 2025 } } }}
My Delphi Objects follow the same structure and that is a bit confusing in my opinion. Is there a way to avoid these unnecessary objects in my Delphi application but keep the mapping intact?
I am looking for something like this. [kbmMW_Element(‘Element.Fields.Year’)]
Thanks in advance!
Hi,
How many fields are we talking about?
If it is only a few, then it perhaps would be easier to either simply load the JSON and use it’s Path method where you can type ‘//Element/Fields’. Eg.
var
n:TkbmMWONNative;
begin
n:=TkbmMWONNative(json.Path(‘//Element/Fields/Year’,[mwonpoLastIsValue]);
if n<>nil then
year:=n.AsInt32;
…
end;
You can even cook that into a specific custom class for the marshaller to use automatically.
Check TkbmMWONStreamMarshal for an example of how to do a custom class marshaller.