Home > Exploring the CodeFluent Runtime > Exploring the CodeFluent Runtime: JsonUtilities

Exploring the CodeFluent Runtime: JsonUtilities

Starting this summer, we added built-in support of JSON/REST services to the WCF Service Model Producer, and around the same period we added a very convenient class to the CodeFluent Runtime (CodeFluent.Runtime.dll): JsonUtilities.

The JsonUtilities class is a simple yet powerful JSON Serializer allowing you to convert your .NET objects into JSON and vice versa. One might ask why didn’t we use one of the many available ones? Well we tried most of them and we bumped into lots of different problems depending on the one used: one supports generics but not serializing the object class, or another one does both but has a strange behavior regarding dates (which by the way is a complex subject in JSON, see this post for more information about this).

Anyway, we thought it could be handy to provide a light JSON serializer (a little more than 1000 lines), which works in .NET 2.0 and upper as well as in Silverlight. Here’s a code sample serializing a collection into JSON:

CustomerCollection customers = CustomerCollection.LoadAll();
string json = JsonUtilities.Serialize(customers);

Keep that in a corner: next time you’ll need to send a JSON stream somewhere, no need to add an extra dependency to your project, you already have what you need in the runtime Smile

Carl Anderson

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s