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/json: string option: decoding struct slices: if field is null in JSON, value gets set to previous struct's field value #9810

Closed
tp opened this issue Feb 8, 2015 · 1 comment

Comments

@tp
Copy link

tp commented Feb 8, 2015

I have seen this with Go 1.2.1 (bundled with App Engine), and could not find a bug report or fix.

This is not an issue with 1.4.1, so I think it has been silently/inadvertently fixed.

package main

import (
    "bytes"
    "encoding/json"
    "fmt"
)

type Container struct {
    Xs []X `json:"xs"`
}

type X struct {
    V int64 `json:"value,string"`
}

func main() {

    content := []byte(`{"xs":[{"value":"5838406743490560"},{"value":null}]}`)
    r := bytes.NewReader(content)

    c := &Container{}
    err := json.NewDecoder(r).Decode(c)
    if err != nil {
        fmt.Println(err.Error())
        return
    }

    fmt.Printf("%d %d", c.Xs[0].V, c.Xs[1].V)
}

http://play.golang.org/p/jE3tFV8dZN

Go 1.2.1 output: "5838406743490560 5838406743490560"
Go 1.4.1 output: "5838406743490560 0"

@minux
Copy link
Member

minux commented Feb 8, 2015

Verified fixed on tip. We don't maintain releases other than
the latest one.

@minux minux closed this as completed Feb 8, 2015
@minux minux changed the title encoding/json string option: decoding struct slices: if field is null in JSON, value gets set to previous struct's field value encoding/json: string option: decoding struct slices: if field is null in JSON, value gets set to previous struct's field value Feb 8, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants