just upgrading my application to SignalR alpha. They have changed the IJsonSerializer interface
with the previous interface I had:
public string Stringify(object obj)
{
var s = "";
s = JsonConvert.SerializeObject(obj, _settings);
return s;
}
and it worked fine.
Now I am trying:
public class CustomJsonNetSerializer : IJsonSerializer
{
private readonly JsonSerializerSettings _settings;
public CustomJsonNetSerializer(JsonSerializerSettings settings)
{
_settings = settings;
}
public object Parse(string json)
{
return JsonConvert.DeserializeObject(json);
}
public object Parse(string json, Type targetType)
{
return JsonConvert.DeserializeObject(json, targetType);
}
public T Parse<T>(string json)
{
return JsonConvert.DeserializeObject<T>(json);
}
public void Serialize(object value, System.IO.TextWriter writer)
{
var s = "";
s = JsonConvert.SerializeObject(value, _settings);
writer.Write(s);
}
}
but now no messages are getting sent back to the clients.
Edited following David’s answer below – this is how I have implemented it – works now with the sample
The below code is of course pointless as it does what the default serialiser does – however I have removed my additions to do with locking objects for simplicity
public class CustomJsonNetSerializer : IJsonSerializer
{
JsonNetSerializer mySerialiser;
public CustomJsonNetSerializer(JsonSerializerSettings settings)
{
mySerialiser = new JsonNetSerializer(settings);
}
public void Serialize(object value, System.IO.TextWriter writer)
{
mySerialiser.Serialize(value, writer);
}
public object Parse(string json, Type targetType)
{
return mySerializer.Parse(json, targetType);
}
}
The easiest way to do this is to use the built in serializer (JsonNetSerializer). Also changing the case of the properties being serialized will break SignalR. We’re working on that.