Deserializing interfaces with Json.NET

Using Json.NET with concrete types is very simple: Just give your object to JsonConvert.Serialize() and give your string to JsonConvert.Deserialize() to get back an instance. Wonderfully simple and convenient.

When you are working with your objects as interfaces, things are only a little more complex during deserialization. With simple objects can simply point the JsonConvert.Deserialize() method to an implementation of your interface. Otherwise, the framework does not have a concrete class to instantiate.

You can just call JsonConvert.Deserialize() to deserialize one of these.

However, what if there are multiple implementation types involved?

You need to tell JsonConvert about your implementation of IMyTransferType as well as the IMyInnerType, but JsonConvert.Deserialize only allows you to specify the parent-most type. To accomplish this, you just need to write simple custom converters. Simply create one class for each of your interface types, inherit from CustomConverter, and have its Create method return a new instance of an implementation:

Use a JsonSerializerSettings class with these classes added to its Converters collection when invoking the JsonConvert.Deserialize method:

Now, JsonConvert will know how to deserialize the child objects as well as the parent-most object.

A return, with hosting in Azure Websites

So, it turns out that deployment of WordPress in Azure Websites is as easy as one could hope.

Exporting all posts from my previous hosting was simple via the wp_admin page’s Tools/Export plugin (once I deleted all pending comments). Then, I upped the maximum upload file size by adding a .user.ini file to the root of the application via WebMatrix, with the following:

upload_max_filesize = 10M

After that, it was a matter of uploading the rest of the site via FTPS. I’m now interested in moving all media to blob storage, but that can come later.

We’re doing Christmas cards

Here is our 2011 Christmas card:

I love the photo and the card (I used my tripod on the beach for the first time!). And, previously this contained a link to the service where we got the cards printed, but since that looked tacky I just posted the photo itself. Much better.

Merry Christmas!

2009 Grandfather Mountain Marathon

I last ran Grandfather Mountain Marathon in 2007 as a training run, and figured it would again be good for hill training. This time DJ joined PM and me, and a great time was had by all.

In 2007 I went out conservatively for the first ten miles, then ran a hard effort to finish up with 3:32. This time I stuck with a more even effort over the entire course, finishing in 3:13 and 13th overall. (However, still only 7th in the 30-39 age group).

Lots of recap and photos behind the link