alexejk / go-xmlrpc

An XML-RPC Client for Go
https://alexejk.io/article/handling-xmlrpc-in-go/
MIT License
19 stars 7 forks source link

Support decoding of a struct nested into an array #85

Closed alexejk closed 6 months ago

alexejk commented 6 months ago

Fixes an issues where responses that have an outer array with a nested struct and other mixed types would not be decoded correctly, throwing a panic.

Example response:

<methodResponse>
  <params>
    <param>
      <value>
        <array>
          <data>
            <value>
              <i4>200</i4>
            </value>
            <value>OK</value>
            <value>
              <struct>
                <member>
                  <name>status</name>
                  <value>OK</value>
                </member>
                <member>
                  <name>contact</name>
                  <value>&lt;sip:raf@192.168.164.128:5060&gt;;expires=60</value>
                </member>
              </struct>
            </value>
          </data>
        </array>
      </value>
    </param>
  </params>
</methodResponse>

Correct way of mapping this response is to

struct{
    Array []any
}

Main issue with decoding this response prior to this PR, would be that any in array type is not assignable as is with decoded types. This PR changes the logic to detect if an interface is mapped when attempting to decode a <struct> and assign a map[string]any to the field instead.

Fixes #84

sonarcloud[bot] commented 6 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
100.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 77.91%. Comparing base (96e03e7) to head (1f615e0).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #85 +/- ## ========================================== + Coverage 77.52% 77.91% +0.39% ========================================== Files 7 7 Lines 565 575 +10 ========================================== + Hits 438 448 +10 Misses 96 96 Partials 31 31 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.