If you're like me and are trying to use DataContractJsonSerializer in a cross-platform codebase, it is easy enough to wrap the JSON.NET API (aka Newtonsoft.Json) in a DataContractJsonSerializer:
using System;
using System.IO;
using System.Reflection;
using Newtonsoft.Json;
namespace System.Runtime.Serialization.Json
{
public class DataContractJsonSerializer
{
private Type type;
private JsonSerializer js;
public DataContractJsonSerializer (Type t)
{
this.type = t;
this.js = new JsonSerializer();
}
public object ReadObject(Stream stream)
{
StreamReader reader = new StreamReader(stream);
return js.Deserialize(reader, type);
}
public void WriteObject(Stream stream, object o)
{
StreamWriter writer = new StreamWriter(stream);
js.Serialize(writer, o);
writer.Flush ();
}
}
}
Of course, that begs the question of why not switch to using the JSON.NET API everywhere... my personal experience with that API is that it can be slower than using DCJS (at least in my informal tests on Windows Phone).
Hope that helps!