FAQ
Hello, go-nutters.
I've hit a problem today with marshaling attributes stored in pointer
fields:
The following struct does not marshal:

type labelcontrol struct {
XMLName xml.Name `xml:"labelcontrol"`
Foo *string `xml:"name,attr"`
}

with the error: xml: unsupported type: *string

I googled and found the following issue (already closed):
https://code.google.com/p/go/issues/detail?id=3719 that describes the same
problem. Looks like only the reading part has been fixed.

I checked again (both in playground and in latest source code as of today)
- the issue is still present.

Luckily I could patch it in just two lines of code, but since the FAQ
states I should ask first, here goes my question. Is my issue genuine? If
so, can I submit the patch?

thanks in advance,
dmitri.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Jan Mercl at Apr 22, 2013 at 7:29 am

    On Sun, Apr 21, 2013 at 6:20 PM, wrote:
    Hello, go-nutters.
    I've hit a problem today with marshaling attributes stored in pointer
    fields:
    The following struct does not marshal:

    type labelcontrol struct {
    XMLName xml.Name `xml:"labelcontrol"`
    Foo *string `xml:"name,attr"`
    }
    BTW, although *string has legitimate uses, they are quite rare. Are
    you sure you need a *string typed field?

    -j

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dmitri Shelenin at Apr 22, 2013 at 8:44 am
    Well, yes, I was kind of hoping it would work. My reasons are I'm combining
    db access with xml serialization so the fields gets tagged both with sql as
    well as xml tags and by virtue of design the column it corresponds to in
    the database is nullable, and I need it as an attribute in an xml.

    Ok, I thought this was a legit but that needs fixing but I have no problem
    having my own copy of xml (and the occasional merge with the trunk from
    time to time).

    thanks,
    dmitri.
    On Monday, April 22, 2013 9:29:11 AM UTC+2, Jan Mercl wrote:

    On Sun, Apr 21, 2013 at 6:20 PM, <dee...@googlemail.com <javascript:>>
    wrote:
    Hello, go-nutters.
    I've hit a problem today with marshaling attributes stored in pointer
    fields:
    The following struct does not marshal:

    type labelcontrol struct {
    XMLName xml.Name `xml:"labelcontrol"`
    Foo *string `xml:"name,attr"`
    }
    BTW, although *string has legitimate uses, they are quite rare. Are
    you sure you need a *string typed field?

    -j
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dan Kortschak at Apr 22, 2013 at 9:18 am
    It should work. Add a note to the issue or open a new one and link to
    the old. You could also contribute your patch.
    On Mon, 2013-04-22 at 01:44 -0700, Dmitri Shelenin wrote:
    Well, yes, I was kind of hoping it would work. My reasons are I'm combining
    db access with xml serialization so the fields gets tagged both with sql as
    well as xml tags and by virtue of design the column it corresponds to in
    the database is nullable, and I need it as an attribute in an xml.

    Ok, I thought this was a legit but that needs fixing but I have no problem
    having my own copy of xml (and the occasional merge with the trunk from
    time to time).

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dmitri Shelenin at Apr 22, 2013 at 8:43 am

    On Sunday, April 21, 2013 6:20:21 PM UTC+2, Dmitri Shelenin wrote:
    Hello, go-nutters.
    I've hit a problem today with marshaling attributes stored in pointer
    fields:
    The following struct does not marshal:

    type labelcontrol struct {
    XMLName xml.Name `xml:"labelcontrol"`
    Foo *string `xml:"name,attr"`
    }

    with the error: xml: unsupported type: *string

    I googled and found the following issue (already closed):
    https://code.google.com/p/go/issues/detail?id=3719 that describes the
    same problem. Looks like only the reading part has been fixed.

    I checked again (both in playground and in latest source code as of today)
    - the issue is still present.

    Luckily I could patch it in just two lines of code, but since the FAQ
    states I should ask first, here goes my question. Is my issue genuine? If
    so, can I submit the patch?

    thanks in advance,
    dmitri.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dmitri Shelenin at Apr 22, 2013 at 9:47 am
    Here's the change I propose:

    diff -r 84e21a8c2137 src/pkg/encoding/xml/marshal.go
    --- a/src/pkg/encoding/xml/marshal.go Sun Apr 21 13:10:19 2013 +0200
    +++ b/src/pkg/encoding/xml/marshal.go Mon Apr 22 11:41:45 2013 +0200
    @@ -285,6 +285,12 @@
    }
    p.WriteString(finfo.name)
    p.WriteString(`="`)
    + // handle pointer values by following the pointer
    + // it's safe to not check for nil since the value has
    + // already been determined to be non-nil
    + if fv.Kind() == reflect.Ptr {
    + fv = fv.Elem()
    + }
    if err := p.marshalSimple(fv.Type(), fv); err != nil {
    return err
    }

    It looks trivial and I hope it is. If it's ok, then I'll try submitting the
    patch/test to the repo by creating an issue.
    Thanks again,
    dmitri.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 21, '13 at 5:43p
activeApr 22, '13 at 9:47a
posts6
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase