Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling Nil in the XML-RPC #84

Open
isaacwein opened this issue Nov 7, 2022 · 6 comments
Open

Handling Nil in the XML-RPC #84

isaacwein opened this issue Nov 7, 2022 · 6 comments

Comments

@isaacwein
Copy link

isaacwein commented Nov 7, 2022

This project is a major help in for me and it freed up a lot of hours of my time.

This is not a bug it is an Enhancement request

but I think that this library is not parsing the nil values from XML-RPC to GO the right way

GO-PLAYGROUND

for example i have this XML-RPC

<?xml version='1.0'?>
<methodResponse>
  <params>
    <param>
      <value>
        <struct>
          <member><name>result</name><value><string>OK</string></value></member>
          <member><name>users</name><value><array><data>
	     <value><struct>
		<member><name>id</name><value><int>123</int></value></member>
		<member><name>name</name><value><string>jack</string></value></member>
		<member><name>vendor</name><value><nil/></value></member>
		<member><name>account_id</name><value><int>1</int></value></member>
		<member><name>number</name><value><string>+12345678900</string></value></member>
             </struct></value>
             <value><struct>
		<member><name>id</name><value><int>123</int></value></member>
                <member><name>name</name><value><string>mark</string></value></member>
                <member><name>vendor</name><value><struct>
                   <member><name>vendor_name</name><value><string>abc.xyz</string></value></member>
                </struct></value></member>
                <member><name>account_id</name><value><int>1</int></value></member>
                <member><name>number</name><value><nil/></value></member>
             </struct></value>
           </data></array></value></member>
        </struct>
      </value>
    </param>
  </params>
</methodResponse>

and I am trying to parse it into this type structure

type ResponseData struct {
	Result string  `xmlrpc:"result"`
	// this will throw an error "error: type mismatch - can't unmarshal invalid to struct"
	// solution: use []User
	Data   []*User `xmlrpc:"users"`
}

type User struct {
	ID        int64   `xmlrpc:"id"`
	Name      string  `xmlrpc:"name"`
	// this will not throw error,
	// but it will define it even it's nil
	Vendor    *Vendor `xmlrpc:"vendor"` // vendor might be nil
	AccountID int64   `xmlrpc:"account_id"`
	// this will not work it will always be empty string even the value is nil
	Number    *string `xmlrpc:"number"` // phone number might be nil
}

type Vendor struct {
	VendorName string `xmlrpc:"vendor_name"`
}

in some cases, it will throw an error, and in some cases it will ignore the XML-RPC nil value and define the pointer as an empty value,
for example, if the XML-RPC has a nullable string and the type has a pointer type of a string the parser shouldn't define the string in a nil case it should leave it nil

@icholy
Copy link
Collaborator

icholy commented Nov 7, 2022

There's this pull request, but it doesn't implement decoding: #75

@SchoolGuy
Copy link

Looking at the spec nil values are not allowed, so whatever API you are talking to might not be XML-RPC. - http://xmlrpc.com/spec.md

@isaacwein
Copy link
Author

isaacwein commented Aug 29, 2024

@SchoolGuy
Copy link

All of the mentioned resources are not the offical spec. Python also has an option to allow None as a type but the option is not spec conform and as such their implementations all differ a bit.

As this library is in minimal maintenance mode I would guess that such a feature is really out of scope.

@isaacwein
Copy link
Author

nil is supported in almost every library i can find there
But I didn't find any mention of it. Besides here
http://1998.xmlrpc.com/bdgChangeNotes.html#nullValues

@SchoolGuy
Copy link

Yes that is true, but that link explicitly names SOAP in its title which is a somewhat similar but different protocol.

https://stackoverflow.com/a/88893/4730773

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants