imulus/Archetype — pull request #107 by cankoluman (2014-04-24 16:02:05+00:00)
Title: Dev/ar 1 serialization - adds uComponents style 'Data Type Objects' serialization

This gives us the ability to serialize / deserialize an arbitrary model into, or from Archetype json.

The serializer uses newtonsoft, and has support for the JsonIgnoreAttribute. It can process simple, enumerable, and compound classes. It handles booleans via 1 / 0 conversion, and also supports nullable types. The below examples are from Archetype.Tests.Serialization.

Usage: decorate the class with
```csharp
[ArchetypeDatatype("")]
[JsonConverter(typeof(ArchetypeJsonConverter))]
public class ClassName {...
```

on a property we can use
```csharp
[JsonProperty("")]
public string PropertyName { get; set; }

[JsonIgnore]
public decimal IgnoreMe { get; set; }
```

Some examples follow:

```csharp
[ArchetypeDatatype("urlPicker")]
[JsonConverter(typeof(ArchetypeJsonConverter))]
public class UrlPicker
{
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("url")]
public string Url { get; set; }
[JsonProperty("content")]
public int? Content { get; set; }
[JsonProperty("media")]
public int? Media { get; set; }
[JsonProperty("openInNewWindow")]
public bool OpenInNewWindow { get; set; }
}

[ArchetypeDatatype("annualStatement")]
[JsonConverter(typeof(ArchetypeJsonConverter))]
public class AnnualStatement
{
public DateTime FiscalYearStart { get; set; }
public DateTime FiscalYearEnd { get; set; }
public DateTime? DividendPaymentDate { get; set; }
public Int32 TotalShares { get; set; }
public Double Sales { get; set; }
public Decimal Profit { get; set; }
}

[ArchetypeDatatype("mergerDetails")]
[JsonConverter(typeof(ArchetypeJsonConverter))]
public class MergerDetails
{
public DateTime MergerDate { get; set; }
[JsonIgnore]
public decimal MergerValue { get; set; }
}

[ArchetypeDatatype("allContactDetails")]
[JsonConverter(typeof(ArchetypeJsonConverter))]
public class AllContactDetails
{
public ContactDetails UserDetails { get; set; }
public ContactDetails AdminDetails { get; set; }

}

[ArchetypeDatatype("contactDetailsList")]
[JsonConverter(typeof(ArchetypeJsonConverter))]
public class ContactDetailsList : List
{
}

[ArchetypeDatatype("contactDetails")]
[JsonConverter(typeof(ArchetypeJsonConverter))]
public class ContactDetails
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("address")]
public string Address { get; set; }
[JsonProperty("telephone")]
public string Telephone { get; set; }
[JsonProperty("mobile")]
public string Mobile { get; set; }
[JsonProperty("fax")]
public string Fax { get; set; }
[JsonProperty("email")]
public string Email { get; set; }
[JsonProperty("webSite")]
public UrlPicker WebSite { get; set; }
}

[ArchetypeDatatype("companyDetails")]
[JsonConverter(typeof(ArchetypeJsonConverter))]
public class CompanyDetails
{
[JsonProperty("region")]
public string Region { get; set; }
[JsonProperty("contactDetails")]
public ContactDetails ContactDetails { get; set; }
}
```