dahomey-technologies/Dahomey.Cbor

[question] define the name of a property on serialization, when manually registered

Closed this issue · 1 comments

Is it possible to define the name of a property on serialization, when manually registering them?

this is my code:

options.Registry.ObjectMappingRegistry.Register<ECKeyPair>(om =>
                    {
                        om.AutoMap();
                        om.ClearMemberMappings();
                        om.MapMember(m => m.PublicKey);
                        om.MapMember(m => m.PrivateKey);
                    });

this will result in the names of the two properties like this: "publicKey" and "privateKey", but, I need it to be "public" and "private"

Yes it's possible!

options.Registry.ObjectMappingRegistry.Register<ECKeyPair>(om =>
                    {
                        om.AutoMap();
                        om.ClearMemberMappings();
                        om.MapMember(m => m.PublicKey).SetMemberName("public");
                        om.MapMember(m => m.PrivateKey).SetMemberName ("private");
                    });

Check here available public methods on the MemberMapping :
https://github.com/dahomey-technologies/Dahomey.Cbor/blob/master/src/Dahomey.Cbor/Serialization/Converters/Mappings/MemberMapping.cs