Skip to content

Instantly share code, notes, and snippets.

@AlexShkor
Created April 11, 2013 17:50
Show Gist options
  • Save AlexShkor/5365573 to your computer and use it in GitHub Desktop.
Save AlexShkor/5365573 to your computer and use it in GitHub Desktop.
SignalR LowerCamelCaseContractResolver repro
var serializer = new MyJsonSerializer();
GlobalHost.DependencyResolver.Register(typeof(IJsonSerializer), () => serializer);
public class LowerCamelCaseContractResolver : DefaultContractResolver
{
protected override string ResolvePropertyName(string propertyName)
{
return String.Format("{0}{1}", propertyName.ToLower()[0], propertyName.Substring(1));
}
}
public class MyJsonSerializer:IJsonSerializer
{
private JsonSerializerSettings _customSettings;
public MyJsonSerializer()
{
_customSettings = new JsonSerializerSettings
{
ContractResolver = new LowerCamelCaseContractResolver()
};
}
public void Serialize(object value, TextWriter writer)
{
writer.Write(JsonConvert.SerializeObject(value, Formatting.None, _customSettings));
}
public object Parse(string json, Type targetType)
{
return JsonConvert.DeserializeObject(json, targetType,_customSettings);
}
}
@AlexShkor
Copy link
Author

Don't use it. use this one
https://gist.github.com/AlexShkor/5371130

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment