Kbmmw_Element  and unnecessary elements

Home Forums kbmMW Kbmmw_Element  and unnecessary elements

Viewing 1 reply thread
  • Author
    Posts
    • #55155
      mrluigi2017
      Participant

      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!

       

       

       

    • #55158
      kimbomadsen
      Keymaster

      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.

      • This reply was modified 5 years, 2 months ago by kimbomadsen.
Viewing 1 reply thread
  • You must be logged in to reply to this topic.