cesanta / ubjson

2 stars 1 forks source link

extra fields should be ignored #6

Closed mkmik closed 8 years ago

mkmik commented 8 years ago
func TestSchemaChange(t *testing.T) {
    a := struct {
        Foo string
        Bar string
    }{"1", "2"}

    var b struct {
        Foo string
    }

    data, err := Marshal(&a)
    if err != nil {
        t.Fatalf("Marshal: %v", err)
    }

    err = Unmarshal(data, &b)
    if err != nil {
        t.Fatalf("Unmarshal: %v", err)
    }
}

We get:

decode_test.go:1461: Unmarshal: expected int type, got string

The test passes with encoding/json.

Furthermore if instead of string we use int, the error is even weirder:

    decode_test.go:1461: Unmarshal: JSON decoder out of sync - data changing underfoot?