Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

danielwertheim/jsonnet-privatesetterscontractresolvers

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 

Replaced

Replaced with new repo and NuGets: https://github.com/danielwertheim/jsonnet-contractresolvers

JsonNet.PrivateSetterContractResolvers

First. I have nothing to do with the awesome official library "Newtonsoft.Json". This is merely a tiny extension to it. In 2010 I was writing a NoSQL'ish document oriented provider over Microsoft SQL Server (SisoDB). While doing this I found the need for a custom contract resolver to Newtonsoft JSON.Net. One that supported private setters as well. I've written about the solutions to this problem before. Since it still seems to solve issues for people I have put up this GitHub repository and created a NuPkg available via NuGet for it as well.

Install-Package JsonNet.PrivateSettersContractResolvers

After that, you just consume it by creating an instance of either:

  • PrivateSetterContractResolver
  • PrivateSetterCamelCasePropertyNamesContractResolver

which you then assign to the JsonSerializerSettings.ContractResolver.

var settings = new JsonSerializerSettings
{
    ContractResolver = new PrivateSetterContractResolver()
};

var model = JsonConvert.DeserializeObject<Model>(json, settings);