Skip to content

DataContractAttribute compatibility should not require IgnoreDataMember #18

Closed

Description

@AArnott

When a class has a [DataContractAttribute] on it, members lacking any [DataMember] attribute should not be serialized, but members with that attribute should be. Instead, MessagePack throws an exception because it requires every member to be explicitly a [DataMember] or [IgnoreDataMember].

For compatibility with existing data contracts where adding attributes is not an option, we should fix MessagePack to accept the same kind of types that the DataContractSerializer and Newtonsoft.Json would.

Activity

  1. self-assigned this
    on Dec 16, 2018
  2. AArnott commented on Dec 16, 2018

    @AArnott
    OwnerAuthor

    See also MessagePack-CSharp#292 where this issue was reported on the upstream project.

  3. fredliex commented on Dec 16, 2018

    @fredliex

    hi @AArnott,

    no existing resolver can simulate DataContractSerializer.
    ex:

    [DataContract]
    public class Master {
        [DataMember]
        public string A { get; set; }
        [DataMember]
        internal Detail B { get; set; }
    }
    public class Detail {
        public string B1 { get; set; }
        internal string B2 { get; set; }
    }
    

    in DataContractSerializer, include A and B1.
    in ContractlessStandardResolver, only A.
    in ContractlessStandardResolverAllowPrivate, include A and B1 and B2, it's too much.

    What do you think?

  4. AArnott commented on Dec 16, 2018

    @AArnott
    OwnerAuthor

    I don't understand what you're suggesting here, and your example doesn't match the scenario that this issue is about, which is this:

    [DataContract]
    public class Master {
        [DataMember]
        public string A { get; set; }
    
        public string B { get; set; }
    }

    When given this, the DynamicObjectResolver throws an exception. This behavior is also specified in the README. This issue tracks removing the exception and ignoring the unattributed member.

  5. AArnott commented on Dec 16, 2018

    @AArnott
    OwnerAuthor

    OK, I think I understand the point you're making now, @fredliex. Thanks for calling out the additional differences in behavior. It's probably worth fixing. But I'd like to track the additional compatibility issues as a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions