Created
April 11, 2013 17:50
-
-
Save AlexShkor/5365573 to your computer and use it in GitHub Desktop.
SignalR LowerCamelCaseContractResolver repro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var serializer = new MyJsonSerializer(); | |
GlobalHost.DependencyResolver.Register(typeof(IJsonSerializer), () => serializer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LowerCamelCaseContractResolver : DefaultContractResolver | |
{ | |
protected override string ResolvePropertyName(string propertyName) | |
{ | |
return String.Format("{0}{1}", propertyName.ToLower()[0], propertyName.Substring(1)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't use it. use this one
https://gist.github.com/AlexShkor/5371130