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

encoding/xml: Un/marshal of struct pointers fails in go1.2rc1 #6556

Closed
eaigner opened this Issue Oct 9, 2013 · 5 comments

Comments

Projects
None yet
5 participants
@eaigner
Copy link
Contributor

eaigner commented Oct 9, 2013

I upgraded to go1.2rc1 and previously working encoding/xml depended code broke.

Consider these 2 structs:

    type SearchQuery struct {
        XMLName string `xml:"search"`
        Fields  []interface{}
    }

    type TextField struct {
    XMLName    xml.Name
    Is         string `xml:"is,omitempty"`
    IsNot      string `xml:"is-not,omitempty"`
    StartsWith string `xml:"starts-with,omitempty"`
    EndsWidth  string `xml:"ends-with,omitempty"`
    Contains   string `xml:"contains,omitempty"`
    }

If SearchQuery contains e.g. TextField pointers, Marshal/Unmarshal fails with

    xml: unsupported type: *package.TextField

If Fields contains plain structs (non-pointers), no error is returned.
@robpike

This comment has been minimized.

Copy link
Contributor

robpike commented Oct 15, 2013

Comment 1:

Labels changed: added priority-soon, go1.2, removed priority-triage.

Status changed to Accepted.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

ianlancetaylor commented Oct 15, 2013

Comment 2:

Can you add a standalone test case?
@eaigner

This comment has been minimized.

Copy link
Contributor Author

eaigner commented Oct 16, 2013

Comment 3:

This test case passes in go1.1.2 and fails in go1.2rc1
package issue6556
import (
    "encoding/xml"
    "testing"
)
func TestStructPointerMarshal(t *testing.T) {
    type A struct {
        XMLName string `xml:"a"`
        B       []interface{}
    }
    type C struct {
        XMLName xml.Name
        Value   string `xml:"value"`
    }
    a := new(A)
    a.B = append(a.B, &C{
        XMLName: xml.Name{Local: "c"},
        Value:   "x",
    })
    b, err := xml.Marshal(a)
    if err != nil {
        t.Fatal(err)
    }
    if x := string(b); x != "<a><c><value>x</value></c></a>" {
        t.Fatal(x)
    }
    var v A
    err = xml.Unmarshal(b, &v)
    if err != nil {
        t.Fatal(err)
    }
}
@eaigner

This comment has been minimized.

Copy link
Contributor Author

eaigner commented Oct 16, 2013

Comment 4:

The unmarshalled object should probably be also verified
@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Oct 17, 2013

Comment 6:

This issue was closed by revision 4dce7f8.

Status changed to Fixed.

@eaigner eaigner added fixed labels Oct 17, 2013

@rsc rsc added this to the Go1.2 milestone Apr 14, 2015

@rsc rsc removed the go1.2 label Apr 14, 2015

@golang golang locked and limited conversation to collaborators Jun 25, 2016

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.