kolo / xmlrpc

Implementation of XMLRPC protocol in Go language.
MIT License
158 stars 92 forks source link

Adding omitempty support for struct Marshalling #70

Closed jakdept closed 4 years ago

jakdept commented 4 years ago

I've modified the encoder to honor a tag of:

`xmlrpc:"tag,omitempty"`

This allows someone to skip sending values that are empty - as defined by reflect.Value.IsZero().

Note, this may be a breaking change? If anyone has a struct with a tag of something,omitempty this will also strip ,omitempty from the end of that tag and possibly not send it? I would expect this would be unintended behavior?

I also added a test to explicitly show what happens when you encode a empty struct:

<value><struct></struct></value>

I don't know if that's intended, and I didn't see anything in the XMLRPC spec about an empty <struct> element, so I don't know if that's right?

icholy commented 4 years ago

What's the exact use-case here? Maybe I'm just lucky, but I've never seen a xmlrpc endpoint with optional parameters.

jakdept commented 4 years ago

You hit it exactly on the head - I'm working against an API that has optional parameters for some calls.

In this case, the methodRoute is always the same, the first param is always an authentication object, the second and third param are actually the routing keys, and the fourth param is the data - sometimes a struct, sometimes a single non-optional value.

Specifying the value in the request as 0 if an integer, or a empty string if a string, is obviously different than not specifying it.

icholy commented 4 years ago

@jakdept thanks for the contribution.