FAQ
Consider this code:
http://play.golang.org/p/SPLchMO1SC

To me, this is unexpected behavior. If a JSON object doesn't match an
explicitly-specified field tag, I expect the Unmarshaler to give up; I
don't expect it to "fall back" and try to match based on variable
name.

Thoughts?

———
My concrete problem is described by this code:
http://play.golang.org/p/HFWHTC1MAC

I'm working around it by naming the variables IntegerId and StringId
(or whatever) but it seems wrong.

--
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

  • Peter Bourgon at Feb 19, 2013 at 3:32 pm

    On Tue, Feb 19, 2013 at 4:20 PM, minux wrote:
    On Tue, Feb 19, 2013 at 11:15 PM, Peter Bourgon wrote:

    Consider this code:
    http://play.golang.org/p/SPLchMO1SC

    To me, this is unexpected behavior. If a JSON object doesn't match an
    explicitly-specified field tag, I expect the Unmarshaler to give up; I
    don't expect it to "fall back" and try to match based on variable
    name.

    Thoughts?

    ———
    My concrete problem is described by this code:
    http://play.golang.org/p/HFWHTC1MAC
    This is documented by the latest document of that package:
    tip.golang.org/pkg/encoding/json
    Quoted below:

    "To unmarshal JSON into a struct, Unmarshal matches incoming object keys to
    the keys used by Marshal (either the struct field name or its tag),
    preferring an exact match but also accepting a case-insensitive match."
    Okay. The parenthetical bit is a bit ambiguous, but I can see how the
    current behavior follows from it. Thanks for the link.

    Still, my expectation is that by explicitly specifying a tag, I'm
    completely overriding Unmarshal's desire to [case-insensitive] match
    against the variable name.

    --
    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.
  • Minux at Feb 19, 2013 at 3:51 pm

    On Tue, Feb 19, 2013 at 11:15 PM, Peter Bourgon wrote:

    Consider this code:
    http://play.golang.org/p/SPLchMO1SC

    To me, this is unexpected behavior. If a JSON object doesn't match an
    explicitly-specified field tag, I expect the Unmarshaler to give up; I
    don't expect it to "fall back" and try to match based on variable
    name.

    Thoughts?

    ———
    My concrete problem is described by this code:
    http://play.golang.org/p/HFWHTC1MAC
    This is documented by the latest document of that package:
    tip.golang.org/pkg/encoding/json
    Quoted below:
    "To unmarshal JSON into a struct, Unmarshal matches incoming object keys to
    the keys used by Marshal (either the struct field name or its tag),
    preferring an exact match but also accepting a case-insensitive match."

    --
    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.
  • Minux at Feb 19, 2013 at 4:41 pm

    On Tue, Feb 19, 2013 at 11:32 PM, Peter Bourgon wrote:
    Still, my expectation is that by explicitly specifying a tag, I'm
    completely overriding Unmarshal's desire to [case-insensitive] match
    against the variable name.
    yes, this occasionally bites me too. But unfortunately we can't change that
    for Go 1.

    --
    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.
  • Russ Cox at Feb 19, 2013 at 7:11 pm
    This is a bug and is fixed at tip. We fixed it months ago but have withheld
    the fix until Go 1.1 because it does change the meaning of some programs.

    Russ

    --
    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.
  • Peter Bourgon at Feb 19, 2013 at 9:21 pm

    On Tue, Feb 19, 2013 at 8:06 PM, Russ Cox wrote:
    This is a bug and is fixed at tip. We fixed it months ago but have withheld
    the fix until Go 1.1 because it does change the meaning of some programs.
    Oh! Cool. Thanks.

    Russ
    --
    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
postedFeb 19, '13 at 3:15p
activeFeb 19, '13 at 9:21p
posts6
users3
websitegolang.org

3 users in discussion

Peter Bourgon: 3 posts Minux: 2 posts Russ Cox: 1 post

People

Translate

site design / logo © 2022 Grokbase