Skip to content

Unable to serialize standalone polymorphic type or collection #171

@isaacabraham

Description

@isaacabraham

I'm using the Redis MsgPack wrapper, but I've tried this separately using the raw MsgPack SDK as well.

I have a simple polymorphic type hierarchy e.g.

type Animal = Cat | Dog

etc. etc., and I want to serialize a list of animals. The problem is that it appears that you need to enclose the list in a type e.g.

type Data = { Animals = ResizeArray<Animal> }

and then place an set of attributes on that property with all of the possible subclasses (or try one of the Runtime attributes).

There are several we face with this approach: -

  1. Every property on every type that has a List of Animal has to have the same attribute / attributes (or perhaps we need to create a custom List that subclasses List etc.). This means attributes all over our types etc.
  2. The bigger issue that is we need to create an enclosing type with a single property just to place the serialization polymorphism information. We should be able to store this information on the types themselves, and / or have a mechanism to do this lookup (similar to how JSON .Net works).

Have we missed something out here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementRequires or request to feature enhancementneed-more-infoNeed more information (error message, stack trace, repro code etc)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions