Skip to content

Custom serializer of enumerable type #25

@darkl

Description

@darkl

Hi, Thanks for the great work on msgpack-cli!

I'm having an issue in the following scenario: I want to implement a custom serializer for a type that I don't own. (it belongs to a dll that I can't modify)

The type implements the IEnumerable interface:

public class Person : IEnumerable<Person>
{
    public string Name { get; set; }

    private IEnumerable<Person> Children { get; set; }

    public IEnumerator<Person> GetEnumerator()
    {
        return Children.GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }
}

I've implemented a custom serializer and registered it:

SerializationContext serializationContext = 
    new SerializationContext();

serializationContext.Serializers.Register(new PersonSerializer());

When I try serialize an instance of the Person class, it works.

But if I try to serialize an array of objects which one of them is an instance of the Person class, I get a NullReferenceException:

object[] array = new object[] {new Person {Name = "Joe"}, 3};

MessagePackSerializer<object[]> context =
    serializationContext.GetSerializer<object[]>();

byte[] packed = context.PackSingleObject(array); // throws NullReferenceException

Thanks for your help,
Elad

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugDetected as bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions