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

Add support for embedded struct fields #61

Closed
wants to merge 1 commit into from

Conversation

awoodbeck
Copy link

This change is meant to address #58 and recurse into embedded structs, pointers to structs, and named structs in order to build the fields map. I also addressed a few linter complaints.

@icholy
Copy link
Collaborator

icholy commented Apr 29, 2019

The problem here is that the marshaling/unmarshaling is not symmetric. Here's what the embedded struct (from your tests) gets marshalled to:

<?xml version="1.0"?>
<value>
  <struct>
    <member>
      <name>Name</name>
      <value>
        <string>Blah</string>
      </value>
    </member>
    <member>
      <name>Status</name>
      <value>
        <struct>
          <member>
            <name>Code</name>
            <value>
              <int>1</int>
            </value>
          </member>
          <member>
            <name>Msg</name>
            <value>
              <string>Test</string>
            </value>
          </member>
          <member>
            <name>Customer</name>
            <value>
              <struct>
                <member>
                  <name>CustomerId</name>
                  <value>
                    <int>1234</int>
                  </value>
                </member>
                <member>
                  <name>CustomerDetails</name>
                  <value>
                    <struct>
                      <member>
                        <name>CustomerName</name>
                        <value>
                          <string>Acme</string>
                        </value>
                      </member>
                      <member>
                        <name>Region</name>
                        <value>
                          <struct>
                            <member>
                              <name>City</name>
                              <value>
                                <string>Somecity</string>
                              </value>
                            </member>
                            <member>
                              <name>State</name>
                              <value>
                                <string>Somestate</string>
                              </value>
                            </member>
                          </struct>
                        </value>
                      </member>
                    </struct>
                  </value>
                </member>
              </struct>
            </value>
          </member>
        </struct>
      </value>
    </member>
    <member>
      <name>S</name>
      <value>
        <struct>
          <member>
            <name>Serial</name>
            <value>
              <int>5678</int>
            </value>
          </member>
        </struct>
      </value>
    </member>
  </struct>
</value>

@awoodbeck
Copy link
Author

I misunderstood the original issue to involve decoding responses. This PR may serve as a starting point for someone to implement the encoding functionality and restore symmetry. I'll close the PR but keep the branch around since I may not have time for at least a week or two.

@awoodbeck awoodbeck closed this Apr 29, 2019
@icholy
Copy link
Collaborator

icholy commented Apr 29, 2019

Marshaling embedded structs should probably work like encoding/json and flatten them out: https://play.golang.org/p/nBgb6jemFTd

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

Successfully merging this pull request may close these issues.

2 participants