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

[enhancement] support non default constructors with non mapped parameters #17

Closed
TMaddox opened this issue Sep 1, 2019 · 1 comment
Closed
Assignees
Labels
enhancement New feature or request

Comments

@TMaddox
Copy link

TMaddox commented Sep 1, 2019

Consider this example:

class Tree
{
        [CborProperty("r")]
        private readonly byte[] _r;

        [CborProperty("s")]
        private readonly byte[] _s;

        [CborConstructor]
        public ECSignature(byte[] r, byte[] s)
        {
            _r = r
            _s = s
        }
}

And this filter approach:

CborOptions.Default.Registry.ObjectMappingRegistry.Register<Tree>(om =>
            {
                om.AutoMap();
                om.ClearMemberMappings();
            });

This will throw right on adding the mapper. I guess this is because there is a [CborConstructor] attribute and there won't be, for example, a "r" or "s" to deserialize, could you just add null, or allow an option to not throw if not all fields can be deserialized?

Or can I use more than one [CborConstructor] and build multiple constructors for each case? (I got different (de)serialization modes and need to be able to serialize one single class in different ways)

@mcatanzariti mcatanzariti self-assigned this Sep 1, 2019
@mcatanzariti mcatanzariti added the enhancement New feature or request label Sep 1, 2019
@mcatanzariti mcatanzariti changed the title [bug] Issue with ObjectMappingRegistry if used alongside attributes [enhancement] support non default constructors with non mapped parameters Sep 1, 2019
@mcatanzariti
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants