Can we add Union attribute support for abstract classes like ZeroFormatter? Limiting it to only interface seems very restrictive. Sometimes we want to have generic implementation in base class.
Thank you for your request.
I think it should be supported and it is possible.
I'll try it.
Cool! That would be awesome! Thanks! 馃憤
Just wanted to ask, has this has been implemented yet?
sorry, not yet.
This would be much welcomed. How do we solve it today? Just add an enum member in each class called type and switch on that?
It would be nice if the Union attribute worked on any class, abstract or not so I can deserialize the base class and then cast it to the concrete subclasses later.
too difficult to how to solve concrete type is union or object in resolver chain.
for example
[Union(0, typeof(SubUnionType1))]
[Union(1, typeof(SubUnionType2))]
[MessagePackObject]
public class RootUnionType
{
[Key(0)]
public int MyProperty { get; set; }
}
// get union formatter
var formatter = formatterResolver.GetFormatter<RootUnionType>();
// but should serialize object formatter, but formatterResolver.GetFormatter<Root> returns union formatter.
formatterResolver.Serialize(new RootUnionType());
If only abstract type or interface, resolver can solve easily.
I've released v1.4.2, it supports UnionAttribute for abstract class.
Fantastic! Will try it out!
Most helpful comment
I've released
v1.4.2, it supports UnionAttribute for abstract class.