Skip to content

Prevent attributes from being serialized #297

Closed
@jaredcnance

Description

@jaredcnance

From @rtablada:

For some models it would be helpful to be able to define which attrs are/aren't used for serializing vs deserializing. [...] Ideally we should be able to declare/override which attrs are used for fetch/create/update operations similar to JSON API resources http://jsonapi-resources.com/v0.9/guide/resources.html#Fetchable-Attributes (we probably can't reproduce this exact API since JADNC uses model decorators instead of a separate resource class)

Proposal

public UserAttributeFilter : IAttributeFilter<User> 
{
    // exclude the User.Password attribute from serialization
    public HashSet<AttrAttribute> ShouldInclude(HashSet<AttrAttribute> attributes)
      => return attributes
            .Where(attr => attr.InternalAttributeName != nameof(User.Password))
            .ToHashSet();
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions