{"id":22076770,"url":"https://github.com/brunozell/privatesettercontractresolver","last_synced_at":"2026-05-18T10:08:41.033Z","repository":{"id":60773932,"uuid":"105518675","full_name":"BrunoZell/PrivateSetterContractResolver","owner":"BrunoZell","description":"Provides a JSON.Net contract resolver to (de-)serialize models with private setters or getter-only auto properties.","archived":false,"fork":false,"pushed_at":"2017-12-05T13:40:05.000Z","size":27,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-20T13:54:45.430Z","etag":null,"topics":["contract-resolver","json","newtonsoft-json"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BrunoZell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-02T09:37:55.000Z","updated_at":"2025-03-07T22:23:26.000Z","dependencies_parsed_at":"2022-10-04T15:29:41.199Z","dependency_job_id":null,"html_url":"https://github.com/BrunoZell/PrivateSetterContractResolver","commit_stats":null,"previous_names":["theinsanebro/newtonsoft.json.serialization.privatesettercontractresolver"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/BrunoZell/PrivateSetterContractResolver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrunoZell%2FPrivateSetterContractResolver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrunoZell%2FPrivateSetterContractResolver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrunoZell%2FPrivateSetterContractResolver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrunoZell%2FPrivateSetterContractResolver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BrunoZell","download_url":"https://codeload.github.com/BrunoZell/PrivateSetterContractResolver/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrunoZell%2FPrivateSetterContractResolver/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280049035,"owners_count":26263866,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-20T02:00:06.978Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["contract-resolver","json","newtonsoft-json"],"created_at":"2024-11-30T22:28:05.378Z","updated_at":"2025-10-20T07:52:39.029Z","avatar_url":"https://github.com/BrunoZell.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PrivateSetterContractResolver\nThis small library provides a JSON.Net contract resolver to (de-)serialize properties with private setters or getter-only auto properties on a model.\n\n    Install-Package PrivateSetterContractResolver\n\nYou can activate the contract resolver using the JsonSettings when (de-)serializing json:\n\n```c#\nusing Newtonsoft.Json;\nusing Newtonsoft.Json.Serialization;\n\nJsonSerializerSettings settings = new JsonSerializerSettings() {\n    ContractResolver = new PrivateSetterContractResolver()\n};\n\n// Use constructor to instantiate the model object\nApiResult model = new ApiResult(\"Error message\");\n\n// Serialize using public getters of the properties\nstring serialized = JsonConvert.SerializeObject(model, settings);\n// { \"success\": false, \"errorMessage\": \"Error message\" }\n\n// Deserialize by using no constructor and directly setting the backing field of the getter-only auto properties\nmodel = JsonConvert.DeserializeObject\u003cModel\u003e(serialized, settings);\n// model has same state right after instantiation\n```\n\nThis contract resolver will not invoke any constructor when deserializing. The combination of setting getter-only auto properties and not using any initialization allows for a very resticted model class for creating valid model instances at runtime without affecting the deserialization process of the receiver. An example would be:\n\n```c#\npublic class ApiResult {\n    /// \u003csummary\u003e\n    /// Creates a successful result with no error message.\n    /// \u003c/summary\u003e\n    public ApiResult() {\n        // This default constructor will NOT be called on deserialization\n        Success = true;\n    }\n\n    /// \u003csummary\u003e\n    /// Creates a failed result with \u003cparamref name=\"errorMessage\"/\u003e as message.\n    /// \u003c/summary\u003e\n    /// \u003cparam name=\"errorMessage\"\u003eThe error message\u003c/param\u003e\n    public ApiResult(string errorMessage) {\n        Success = false;\n        ErrorMessage = errorMessage;\n    }\n\n    public bool Success { get; }\n    public string ErrorMessage { get; }\n}\n```\n\nThis model implements a default constructor in which the model is set in a successful state. This parameterless constructor would be called by default and the Success-Property wouldn't be changed to it's real value anymore since it's a getter-only auto property. With the PrivateSetterContractResolver however no constructor will be called at all and the getter-only property will be set to the correct value.\n\nUsing uninitialized objects can be dangerous, so use this contract resolver only in places where initialization is generally not needed (like in serializing api models).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrunozell%2Fprivatesettercontractresolver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrunozell%2Fprivatesettercontractresolver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrunozell%2Fprivatesettercontractresolver/lists"}