Deserializing XML to C# child class -
my xml :
<?xml version="1.0" encoding="utf-8"?> <response id="41cc788a-bc22-4ce0-8e1c-83bf49bbffed"> <message>successfully processed request</message> <payload>alive</payload> </response>
my classes :
[xmlroot("response")] [serializable] public abstract class esbresponsebase<t> { [xmlattribute] public string id { get; set; } public string message { get; set; } public t payload { get; set; } } [xmlroot("response")] [serializable] public class esbresponseisalive : esbresponsebase<string> { }
note if don't have these classes on child classes throws exception seems inheritance doesn't work these.
my serialization code :
xmlserializer serializer = new xmlserializer(typeof (esbresponseisalive)); var esbresponseisalive = (esbresponseisalive) serializer.deserialize(result);
however when serialize object properties null.
i think more issue inheritance in classes used serializing. possible change base class actual concrete class , use generic, preferred have typed.
as turns out, xmlserializer case-sensitive. class looks following , works.
[xmlattribute("id")] public string id { get; set; } [xmlelement("message")] public string message { get; set; } [xmlelement("payload")] public t payload { get; set; }
Comments
Post a Comment