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
{{ message }}
Repository navigation
DataContractSerializer can serialize without IgnoreDataMember, but MessagePack can't #292
Hi,
I'm trying to change DataContractSerializer with MessagePack in our local wcf service and clients. But MsgPack serializer can't serialize if a public member doesnt have any DataMember or IgnoreDataMember attributes, even if I use Contractless resolver:
using System.Runtime.Serialization;
using MessagePack;
[DataContract]
public class Asd
{
[DataMember]
public string Member { get; set; }
public string NotMember { get; set; }
}
var asd = new Asd {
Member = "Member",
NotMember = "NotMember"
};
var resolver = MessagePack.Resolvers.ContractlessStandardResolver.Instance;
var s = LZ4MessagePackSerializer.Serialize(asd, resolver);
LZ4MessagePackSerializer.Deserialize<Asd>( s, resolver).Dump();
I can't add IgnoreDataMember everywhere because some models have been generated by wcf client proxy generation. Especially, all proxy generated models have ExtensionData property which is not marked with IgnoreDataMember and it is public.
How can we ignore requirement of IgnoreDataMember?
Add MessagePackObjectAttribute to the types you need to serialize and deserialize with message pack. To custom properties serialization you could always implement your own Type Formatter were you specify what properties you will want to serialize and deserialize. Check this github repository where I show an example of that!
On that repository there is a library were I implement IMessagePackFormatter.
The TypeMessagePackFormatter allows you to register specific behaviour to your properties on the ctor. If you do not want to serialize some of the instance properties you do not register an handler to that property.
I can't add MessagePackObjectAttribute to a generated class by wcf client proxy. Yet, I can't specify any type based formatter neither, because if I update service reference, new types might come to surface. I need to serialize and deserialize these proxy generated classes without changing a bit. I'll try to check IMessagePackFormatter if it works. But I'm concerned about performance if I do that. By the way, I've pointed out IgnoreDataMember exception when the class has DataContract.
Same issue: we have models from MS Dynamics CRM SDK and we want to serialize/deserialize them in binary somehow. They are properly marked with [DataContract], [DataMember]: they work perfectly fine with DataContractSerializer and WCF, but have unmarked public properties and MessagePack throws an exception. Why not make an appropriate resolver which ignores unmarked fields? Or if it's not reslover's responsibility, then maybe add an option somewhere to ignore unmarked fields instead of throwing?
Activity
vpaulino commentedon Jul 23, 2018
Add MessagePackObjectAttribute to the types you need to serialize and deserialize with message pack. To custom properties serialization you could always implement your own Type Formatter were you specify what properties you will want to serialize and deserialize. Check this github repository where I show an example of that!
On that repository there is a library were I implement IMessagePackFormatter.
The TypeMessagePackFormatter allows you to register specific behaviour to your properties on the ctor. If you do not want to serialize some of the instance properties you do not register an handler to that property.
oruchreis commentedon Jul 24, 2018
I can't add MessagePackObjectAttribute to a generated class by wcf client proxy. Yet, I can't specify any type based formatter neither, because if I update service reference, new types might come to surface. I need to serialize and deserialize these proxy generated classes without changing a bit. I'll try to check IMessagePackFormatter if it works. But I'm concerned about performance if I do that. By the way, I've pointed out IgnoreDataMember exception when the class has DataContract.
Rast1234 commentedon Aug 14, 2018
Same issue: we have models from MS Dynamics CRM SDK and we want to serialize/deserialize them in binary somehow. They are properly marked with
[DataContract], [DataMember]: they work perfectly fine with DataContractSerializer and WCF, but have unmarked public properties and MessagePack throws an exception. Why not make an appropriate resolver which ignores unmarked fields? Or if it's not reslover's responsibility, then maybe add an option somewhere to ignore unmarked fields instead of throwing?fredliex commentedon Dec 1, 2018
I create a PR #350
add a resolver to simulate behavior like DataContractSerializer.
Support [DataContract] types that lack explicit [IgnoreMember] attrib…
Bump dotnet-coverage from 17.12.4 to 17.12.5 (#292)