tukarambande / xmlrpcnet

Automatically exported from code.google.com/p/xmlrpcnet
0 stars 0 forks source link

XmlRpcServiceInfo class should allow members of non XML-RPC-valid types but with NonSerializedAttribute set #50

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hello. I'm having problem with serializing struct that contains non
XML-RPC-valid field types but with NonSerializedAttribute set. I think that
XmlRpcServiceInfo class should allow such cases.

For example it should allow serializing of this:

public struct Test 
{
  [NonSerialized]
  public long NonXmlRpcValidButNotSerialized;
  public int XmlRpcValidAndSerialized;
}

Attached a .patch that corrects XmlRpcServiceInfo behaviour.

Original issue reported on code.google.com by pingw33n@gmail.com on 2 Mar 2009 at 7:55

Attachments:

GoogleCodeExporter commented 8 years ago
Hi Pingw33n,

What I think your doing is already defined in the framework. You will want to 
set the
attribute on your struct like so:

[XmlRpcMissingMapping(MappingAction.Ignore)]
public struct Test 
{
  [NonSerialized]
  public long NonXmlRpcValidButNotSerialized;
  public int XmlRpcValidAndSerialized;
}

You can set it on the individual method.

For more information see Question "1.15 Can I specify struct members as 
optional?" at
http://www.xml-rpc.net/faq/xmlrpcnetfaq.html

Hope that helps. 

Original comment by Aaron.Mo...@gmail.com on 3 Mar 2009 at 3:37

GoogleCodeExporter commented 8 years ago
Hello. Thanks for a reply. 
Actually that won't work, because XmlRpcMissingMappingAttribute with
MappingAction.Ignore only directs to not serialize members that have null value:

// XmlRpcSerializer.cs:741
if (pi.GetValue(o, null) == null)
{
  MappingAction memberAction = MemberMappingAction(o.GetType(),
    pi.Name, structAction);
  if (memberAction == MappingAction.Ignore)
    continue;
}

And actual XML writing occurs after a call to
XmlRpcServiceInfo.GetXmlRpcType(o.GetType()) that returns XmlRpcType.tInvalid 
because
it doesn't respect NonSerializedAttribute of one or more struct members.
Basically XmlRpcServiceInfo.GetXmlRpcType should return XmlRpcType.tStruct for
structs and classes that has non XML-RPC-valid members but which are marked with
NonSerializedAttribute. 

Original comment by pingw33n@gmail.com on 3 Mar 2009 at 10:02

GoogleCodeExporter commented 8 years ago
Fixed as for issue 78.

Original comment by ChasC...@gmail.com on 13 Mar 2011 at 3:21