Tiny solution providing pre-made ContractResolver
implementations for Newtonsoft.Json, resolvers that supports private property setters and private constructors.
Previous repo and NuGet distributions that this repo replaces are:
- https://github.com/danielwertheim/jsonnet-privatesetterscontractresolvers
- https://www.nuget.org/packages/JsonNet.PrivateSettersContractResolvers/
- https://www.nuget.org/packages/JsonNet.PrivateSettersContractResolvers.Source/
Install-Package JsonNet.ContractResolvers
After that, you just consume it by creating an instance of either:
PrivateSetterContractResolver
- extendsDefaultContractResolver
with support for private setters.PrivateSetterAndCtorContractResolver
- extendsDefaultContractResolver
with support for private setters and private constructors.PrivateSetterCamelCasePropertyNamesContractResolver
- extendsCamelCasePropertyNamesContractResolver
with support for private setters.PrivateSetterAndCtorCamelCasePropertyNamesContractResolver
- extendsCamelCasePropertyNamesContractResolver
with support for private setters and private constructors.
which you then assign to the JsonSerializerSettings.ContractResolver
.
var settings = new JsonSerializerSettings
{
ContractResolver = new PrivateSetterContractResolver()
};
var model = JsonConvert.DeserializeObject<Model>(json, settings);