fabriciocolombo / delphi-rest-client-api

A Delphi REST client API to consume REST services written in any programming language.
Apache License 2.0
380 stars 182 forks source link

Impliment support attributes for marshal/unmarshal #41

Closed Frees closed 9 years ago

Frees commented 9 years ago

Since Delphi 2010 available attributes http://docwiki.embarcadero.com/RADStudio/2010/en/Declaring_Custom_Attributes

We can use it for improve marshal/unmarshal

For example:

TSomeObject = class
   [TJsonField('fieldA')]
   filedAlpha: string;
end;

it'll be marshaled to (or unmarshal from)

{"fieldA" : "someValue"}
RobertoSchneiders commented 9 years ago

Yeah, that seems great. :+1:

Frees commented 9 years ago

I`ll try implement my idea

fabriciocolombo commented 9 years ago

This is already supported. SuperObject implements the attributes SOName and SODefault. When using DBX there are the attributes JsonName and JsonDefault defined in DbxJsonUtils unit.

See the code inside TypesToTest.TAllTypes and the tests inside TestDbxJsonUnMarshal

TAllTypes = class
  [SOName('renamed')]
  [JsonName('renamed')]
  fieldNameRenamed: String;

Maybe this could be improved. Maybe remove the duplicated attribute. Anyway, The docs should be improved to expose this feature.

Thanks.

Frees commented 9 years ago

Thanks Fabricio