title: Customise NewtonSoft.Json for Value Object serialisation
body: <p>Sometimes, perhaps in a DDD situation, you might want to use C# to create Value Objects to represent data, to give more meaning to your domain than using primitive types would, with the added benefit of being immutable.</p>
  
  <p>For example:</p>
  
  <pre><code>public class PostalCode // Bit like a zipcode
  {
      public string Value { get; private set; }
  
      public PostalCode(string value)
      {
          Value = value;
      }
  
      // Maybe sprinkle some ToString()/Equals() overrides here
  }
  </code></pre>
  
  <p>Bravo. Well done me.</p>
  
  <p>The only thing is, when serialised to Json, you get this:</p>
  
  <pre><code>{
      "Value": "W1 AJX"
  }
  </code></pre>
  
  <p>That sort of looks okay, but when it's used as a property of an object (let's say an address) then it looks like this:</p>
  
  <pre><code>{
    "Line1": "Line1",
    "Line2": "Line2",
    "Line3": "Line3",
    "Town": "Town",
    "County": "County",
    "PostalCode": {
      "Value": "W1 AJX"
    }
  }
  </code></pre>
  
  <p>Taken to an extreme, you can see there's a lot of noise here. What I'd like to do, is tell Newtonsoft.Json, that when it sees a type of <code>PostalCode</code>, that it can serialise it to a string value (and vice versa). That would result in the following json:</p>
  
  <pre><code>{
    "Line1": "Line1",
    "Line2": "Line2",
    "Line3": "Line3",
    "Town": "Town",
    "County": "County",
    "PostalCode": "W1 AJX"
  }
  </code></pre>
  
  <p>Is this achievable? I've had a look through the docs and I suspect a custom <code>JsonConverter</code> might be the way forward?</p>