Comments (6)
@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?:
- Register default implementation to SerializationRepository, and ALL serializers refer them.
- Annotate individual properties with a custom attribute (it might be MessagePackMemberAttribute) to specify default implementation.
from msgpack-cli.
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.
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:
- 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).
- 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.
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.
Thank you. I will design and implement it with your side note in mind.
from msgpack-cli.
I added this feature to 0.4 release.
from msgpack-cli.
Related Issues (20)
- Unpacker throws exception trying to read map length after IsMapHeader returns true HOT 1
- Buffering causes async unpacking to fail HOT 2
- Add a non-generic override to SerializerRepository
- EnumMemberAttribute does not work. (expectedly)
- Type Object in MessagePack HOT 1
- GetMemberName() causes NullReferenceException when using MessagePackSerializer.Get<T>() in Xamarin iOS
- [Unity][il2cpp]'class' is not registered in this resolver,resolver.StandardResolver HOT 2
- How to serialize and deserialize a List member in a class HOT 2
- Problem deserializing byte array - InvalidOperationException caused by Decoders.InvalidArrayHeader.Read call HOT 4
- about LZ4 HOT 1
- Unable to cast object of type on netcore HOT 1
- Custom Serialisation docs appear to be out of date. HOT 1
- PackAsync & UnpackAsync not working when passing data continuously using for loop c# HOT 1
- The unpacked value is not expected type HOT 2
- Authenticode Signing? HOT 2
- DateTime serialization and deserialization timezone HOT 3
- Enum Deserialization Not working? HOT 1
- Serializer.Unpack Continuosly Stream of Data => High Memory Usage HOT 3
- Serialization / deserialization speed optimizations HOT 2
- Serialization field order by declaration order HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from msgpack-cli.