Last active
May 23, 2017 09:58
-
-
Save MrAntix/47efb3bc249199cee4e7a151ca6e3ac3 to your computer and use it in GitHub Desktop.
Configure JSON.NET for camels and dates
This file contains hidden or 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 SpecialCamelCasePropertyNamesContractResolver : | |
CamelCasePropertyNamesContractResolver | |
{ | |
protected override JsonDictionaryContract CreateDictionaryContract( | |
Type objectType) | |
{ | |
var contract = base.CreateDictionaryContract(objectType); | |
contract.DictionaryKeyResolver = propertyName => propertyName; | |
return contract; | |
} | |
} |
This file contains hidden or 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 static HttpConfiguration ConfigureForJson( | |
this HttpConfiguration configuration) | |
{ | |
var formatter = configuration.Formatters.JsonFormatter; | |
formatter.SerializerSettings.ContractResolver | |
= new SpecialCamelCasePropertyNamesContractResolver(); | |
configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add( | |
new IsoDateTimeConverter() | |
{ | |
DateTimeFormat = "yyyy-MM-ddTHH:mmZ" | |
}); | |
configuration.Formatters.Clear(); | |
configuration.Formatters.Add(formatter); | |
return configuration; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment