Skip to content

Support private setter #129

@endeffects

Description

@endeffects

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;
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions