JSONMarshal: Can I serialize / describe to / from "plain" JSON (no metadata)?

I'm writing a Rest DataSnap Client (in Delphi) and I want it to provide json data for many platforms (e.g. C #, java, C ++, Delphi). I am using TJsonMarshal

to serialize an object. I am using something similar to this:

marshal := TJSONMarshal.Create(TJSONConverter.create);
jsonString := marshal.marshal(myObject).ToString;

      

But when I do that, the generated JSON looks something like this:

{"type":"WJsonObj.TWPedido","id":1,"fields":
  {"Numero":1234,"Data":41606.7632623727,"VlrTotal":2543,
  "Produtos":
    [{"type":"WJsonObj.TWProdutoPedido","id":2,"fields":
      {"Codigo":"P001","Descr":"Computador","Qtde":1,"VrUnitario":1500}},

...

      {"type":"WJsonObj.TWProdutoPedido","id":4,"fields":
        {"Codigo":"P003","Descr":"Projetor","Qtde":1,"VrUnitario":745}}
    ]
  }
}

      

And I just wanted JSON, no metadata ( 'type'

, 'id'

and 'fields'

), so I wouldn't have unnecessary json parsing on non-Delphi platforms. Is there a way to make it TJsonMarshal

serialize to "plain" JSON?

+3


source to share


1 answer


You must use System.JSON

and REST.JSON

instead of Data.DBXJson

andData.DBXJSONReflect



var
  foo, newfoo: TFoo;
  s: string;

  foo := TFoo.Create;
  s := TJson.ObjectToJsonString(foo);

  newfoo := TJson.JsonToObject<TFoo>(s);

      

+4


source







All Articles