Git Product home page Git Product logo

Comments (6)

yfakariya avatar yfakariya commented on July 18, 2024

@amirabiri
Thank you nice feedback.

As you guess, serializing interfaces or abstract classes are problematic because serializer cannot determine what type should be used to deserialize object. MessagePack stream itself does not contain any information of original type.
However your suggestion that serializers fall back to default generic collection implementation for abstract collection types is useful solution.

So, may I ask you a question?

I have two options to implement your idea, which one is preferred do you think?:

  1. Register default implementation to SerializationRepository, and ALL serializers refer them.
  2. Annotate individual properties with a custom attribute (it might be MessagePackMemberAttribute) to specify default implementation.

from msgpack-cli.

amirabiri avatar amirabiri commented on July 18, 2024

I think there should always be a non-attribute way since attributes are still somewhat invasive.

I would go with both options - configurable defaults in the context options, with the basic collection already configured + ability to override concrete type on a per-property basis using attributes.

For the basic pre-set collections I would support IList, IList<>, IDictionary, IDictionary<>. I'm not sure I would bother with the rest as they are not common data-object paradigms, and if the user can always add them to the context I think that's enough.

from msgpack-cli.

yfakariya avatar yfakariya commented on July 18, 2024

Thank you amirabiri.

I will go with pre-set collections in the context options, and will not support individual properties directly because specifying special concrete types is not very common. Instead, you have already have following work arounds:

  1. Make the property/field read-only and instantiate concrete object on constructor/initializer. MessagePack for CLI supports such properties (just call Add(T) method of it instead of assign collection itself).
  2. Implements IUnpackable or custom serializer to support special types.

Here is an example of option 1:

public class Foo
{
    private readonly IList<int> _list = new Collection<int>();
    public IList<int> List{ get { return _list; } }
}

What do you think about it?

from msgpack-cli.

amirabiri avatar amirabiri commented on July 18, 2024

I think it's good.

A side note - you should make sure the user can specify generic classes without arguments, i.e so that one can register a custom handler for IList<> rather than IList<string>. Note that you can't do that with a simple Register<> because in such a case the user must specify all type arguments, but with Register(Type type) you can, because you can do Register(typeof(IList<>)), but you can't do Register<IList<>>().

from msgpack-cli.

yfakariya avatar yfakariya commented on July 18, 2024

Thank you. I will design and implement it with your side note in mind.

from msgpack-cli.

yfakariya avatar yfakariya commented on July 18, 2024

I added this feature to 0.4 release.

from msgpack-cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.