You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unfortunately, GetSerializer<T> doesn't seem to work, presumably as the properties of anonymous types are read only. Because the returned serializer can both serialise and deserialise, it's not possible to build it. However we only need the serialiser bit.
In my unstanding, anon types cannot be take away from declaring method, so I cannot imagine use case when anon type serialization is really useful. Would you tell me when and how do you use anon types serialization?
Anonymous classes are regular classes and their type can be known and passed around. This is especially easy when using generic methods:
public void Log<T>(LogLevel level, T data)
{
_serializationContext.GetSerializer<T>()
.Pack(_logStream, new { Level = level, Data = data });
}
That's actually pretty close to our use case. The logging API should support arbitrary data from users, so long as it only contains serialisable types. However the anonymous type simply isn't serialisable.
The problem seems to be that msgpack-cli uses one set of restrictions across both encodable/decodable types. This means types must always have read/write properties in order to work with the lib. This seems like a significant limitation, especially when you use immutability extensively in your code.
Of course it's not limited to anonymous types:
public class Foo { public string Name { get; private set; } /*...*/ }
_serializationContext.GetSerializer<Foo>() // bang!
In this case, as with anonymous types, Foo is definitely serialisable, however it is not deserialisable. If There is definitely a strong use-case for treating serialiser and deserialiser types separately.
Thank you for great suggestion. I understand that there are use cases that need 'asymmetric' serializer which only available for serialization or deserialization. Although I'm interested in asymmetric serializers feature, I cannot tuckle to it soon because I'm working on another issue.
This would certainly be very useful for us. I'm not sure how hard it would be to retrofit this to the current API. I suppose the current serialiser objects could implement both IPacker<T> and IUnpacker<T> or something like that, and then it would also be possible to generate just one or the other:
_serializationContext.GetPacker<Foo>().Pack(new Foo()); // ok
_serializationContext.GetUnpacker<Foo>().Unpack(new Foo()); // bang!
Activity
yfakariya commentedon Feb 28, 2015
In my unstanding, anon types cannot be take away from declaring method, so I cannot imagine use case when anon type serialization is really useful. Would you tell me when and how do you use anon types serialization?
drewnoakes commentedon Mar 2, 2015
Anonymous classes are regular classes and their type can be known and passed around. This is especially easy when using generic methods:
That's actually pretty close to our use case. The logging API should support arbitrary data from users, so long as it only contains serialisable types. However the anonymous type simply isn't serialisable.
The problem seems to be that msgpack-cli uses one set of restrictions across both encodable/decodable types. This means types must always have read/write properties in order to work with the lib. This seems like a significant limitation, especially when you use immutability extensively in your code.
Of course it's not limited to anonymous types:
In this case, as with anonymous types,
Foois definitely serialisable, however it is not deserialisable. If There is definitely a strong use-case for treating serialiser and deserialiser types separately.[-]Serialising anonymous types[/-][+]Serialising anonymous/immutable types[/+]yfakariya commentedon Mar 2, 2015
Thank you for great suggestion. I understand that there are use cases that need 'asymmetric' serializer which only available for serialization or deserialization. Although I'm interested in asymmetric serializers feature, I cannot tuckle to it soon because I'm working on another issue.
drewnoakes commentedon Mar 3, 2015
This would certainly be very useful for us. I'm not sure how hard it would be to retrofit this to the current API. I suppose the current serialiser objects could implement both
IPacker<T>andIUnpacker<T>or something like that, and then it would also be possible to generate just one or the other:Implement asymmetric serializers. #68
yfakariya commentedon Sep 26, 2017
This was implemented in 0.9.
drewnoakes commentedon Sep 28, 2017
Great news!