Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support private setter #129

Open
endeffects opened this issue Jun 7, 2019 · 0 comments
Open

Support private setter #129

endeffects opened this issue Jun 7, 2019 · 0 comments

Comments

@endeffects
Copy link

endeffects commented Jun 7, 2019

I need to deserialize a document into a domain type where the properties have only private setters and no constructor is available.

In your implementation you don't allow to override the DefaultContractResolver because you recreate it each time the db connection is used, so i'm not able to resolve this by my own without creating new models.

So would you please allow overriding the DefaultContractResolver or add the following workaround to the current implementation?

Pull request: #130

    public class NonPublicPropertiesResolver : DefaultContractResolver
    {
        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
        {
            var prop = base.CreateProperty(member, memberSerialization);
            if (!(member is PropertyInfo pi)) { return prop; }

            prop.Readable = (pi.GetMethod != null);
            prop.Writable = (pi.SetMethod != null);

            return prop;
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant