FAQ
Hi,

Wondering if I could get a hand with the following
example: http://play.golang.org/p/2AJV99RGaw

I believe the type assertion on line 35 should succeed, but instead it
panics.

Bug or am I misusing the type system?

Alex

--
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Jesse McNelis at Jan 7, 2014 at 12:21 am

    On Tue, Jan 7, 2014 at 11:15 AM, Alex Zorin wrote:

    Hi,

    Wondering if I could get a hand with the following example:
    http://play.golang.org/p/2AJV99RGaw

    I believe the type assertion on line 35 should succeed, but instead it
    panics.

    Bug or am I misusing the type system?
    The json docs are pretty clear on what types you should expect in json
    unmarshaled in to an interface{} value.
    http://golang.org/pkg/encoding/json/#Unmarshal


      --
    =====================
    http://jessta.id.au

    --
    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 [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
  • Alex Zorin at Jan 7, 2014 at 12:27 am
    Thank you Jesse, I can see why the limitation might be in place.

    I'll have to look later to see whether it might be possible to improve the
    unmarshaler to determine more precise type information without killing the
    performance completely.

    Alex
    On Tuesday, January 7, 2014 11:21:24 AM UTC+11, Jesse McNelis wrote:

    On Tue, Jan 7, 2014 at 11:15 AM, Alex Zorin <[email protected] <javascript:>>wrote:
    Hi,

    Wondering if I could get a hand with the following example:
    http://play.golang.org/p/2AJV99RGaw

    I believe the type assertion on line 35 should succeed, but instead it
    panics.

    Bug or am I misusing the type system?
    The json docs are pretty clear on what types you should expect in json
    unmarshaled in to an interface{} value.
    http://golang.org/pkg/encoding/json/#Unmarshal


    --
    =====================
    http://jessta.id.au
    --
    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 [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jesse McNelis at Jan 7, 2014 at 12:32 am

    On Tue, Jan 7, 2014 at 11:27 AM, Alex Zorin wrote:

    Thank you Jesse, I can see why the limitation might be in place.

    I'll have to look later to see whether it might be possible to improve the
    unmarshaler to determine more precise type information without killing the
    performance completely.
    If you want a specific type then you need to pass that in to unmarshal.
    http://play.golang.org/p/CgumnODUn2

    --
    =====================
    http://jessta.id.au

    --
    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 [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
  • Matt Harden at Jan 7, 2014 at 1:37 am
    There might be a misunderstanding here. Package encoding/json, like
    encoding/xml, does not store type information along with the data in
    marshal(). Instead it is designed to use the most natural json encoding to
    interoperate with other tools and languages. If you need type information
    included in the encoding, you need something like encoding/gob.

    On Mon, Jan 6, 2014 at 6:32 PM, Jesse McNelis wrote:
    On Tue, Jan 7, 2014 at 11:27 AM, Alex Zorin wrote:

    Thank you Jesse, I can see why the limitation might be in place.

    I'll have to look later to see whether it might be possible to improve
    the unmarshaler to determine more precise type information without killing
    the performance completely.
    If you want a specific type then you need to pass that in to unmarshal.
    http://play.golang.org/p/CgumnODUn2

    --
    =====================
    http://jessta.id.au

    --
    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 [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    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 [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 7, '14 at 12:15a
activeJan 7, '14 at 1:37a
posts5
users3
websitegolang.org

People

Translate

site design / logo © 2023 Grokbase