Add support to change the json property names when serializing/deserializing
fabio-costa-souza opened this issue · comments
Is it possible to have one field in the class, but different names for it during serialization/deserialization?
Something like this:
public class Videogame
{
private:
[JsonProperty("name")]
string Name;
[JsonProperty("release_date")]
private DateTime ReleaseDate;
}
Videogame starcraft = new Videogame
{
Name = "Starcraft",
ReleaseDate = new DateTime(1998, 1, 1)
};
string json = ThorsAnvil::Serialize::jsonExport(starcraft);
Console.WriteLine(json);
// {
// "name": "Starcraft",
// "release_date": "1998-01-01T00:00:00"
// }
You can do it by adding your traits. Actually they are poorly documented(but still mentioned on another site) but the framework is not hard to understand while not documented at all
Done:
Use the macros:
- ThorsAnvil_MakeTraitName_Override
- ThorsAnvil_Template_MakeTraitNameOverride
Check Examples here: https://github.com/Loki-Astari/ThorsSerializer/blob/master/src/Serialize/test/OverrideIdentiferToKeyMapTest.cpp