FAQ
Hi,

I have run into a problem of failing to be able to Marshal and Unmarshal
structures which implement an interface but their JSON-signatures are the
same, i.e:

type some_error struct{
    Message string `json,message`
    ErrorCode string `json,errorCode`
}

type some_error struct2{
    Message string `json,message`
    ErrorCode string `json,errorCode`
}

Initially I was thinking of including an error type name as part of JSON
message which would be used to guide the unmarshaller but was wondering if
there are better ways to do that?

Best,
Marek

--
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/d/optout.

Search Discussions

  • Chris Broadfoot at Mar 30, 2016 at 11:47 pm
    Yes, you'll need something to be able to differentiate the type to
    unmarshal into.

    Something along these lines:
    http://play.golang.org/p/7JrdZq3dmO
    On Wed, Mar 30, 2016 at 10:42 AM, Marek Romanowicz wrote:

    Hi,

    I have run into a problem of failing to be able to Marshal and Unmarshal
    structures which implement an interface but their JSON-signatures are the
    same, i.e:

    type some_error struct{
    Message string `json,message`
    ErrorCode string `json,errorCode`
    }

    type some_error struct2{
    Message string `json,message`
    ErrorCode string `json,errorCode`
    }

    Initially I was thinking of including an error type name as part of JSON
    message which would be used to guide the unmarshaller but was wondering if
    there are better ways to do that?

    Best,
    Marek

    --
    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/d/optout.
    --
    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/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 30, '16 at 11:33p
activeMar 30, '16 at 11:47p
posts2
users2
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase