This repository was archived by the owner on Jun 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Saving the data as Json
Pure Krome edited this page Feb 1, 2016
·
1 revision
The object model includes some extra meta data about wether or not an piece of data has been modified or not. This is used when copying some source
listing object to a destination
object. Which fields to we include?
As such, it's nice (but not madatory) to save the data to a json file format and to exclude this data modified status. Basically, save all the data but exclude the DataModified
property.
The trick is to use the ListingConverter
which has been provided for you.
This is how you can do it using Newtonsoft.Json
:
var jsonSettings = new JsonSerializerSettings
{
Converters = new JsonConverter[] { new ListingConverter() },
};
var json = JsonConvert.SerializeObject(listing, jsonSettings);
The custom converter is not required when de-serializing, because the source json (to deserialize) should not have any DataModified
key/values in it 😄