Closed johnniedoe closed 8 years ago
Difference between encoders.
At the edges, these sort of differences are not surprising.
Fair enough.
While I was looking into this, I did find another interesting case. With the same program, if you instead have the structs
type Composite struct {
X string
Embedded
}
type Embedded struct {
Y string `json:"X"`
}
The stdlib version will not encode the embedded value, while codec will produce an encoded value with two "X" fields.
json: {"X":"a"}
codec: {"X":"a","X":"b"}
In this case, it's unclear what the receiver of such a payload might do with it. Granted, it's also a problem that can usually be avoided w/more judicious use of struct tags.
This is a bug! On Jun 10, 2016 7:23 AM, "johnniedoe" notifications@github.com wrote:
Fair enough.
While I was looking into this, I did find another interesting case. With the same program, if you instead have the structs
type Composite struct { X string Embedded }
type Embedded struct { Y string
json:"X"
}The stdlib version will not encode the embedded value, while codec will produce an encoded value with two "X" fields.
json: {"X":"a"} codec: {"X":"a","X":"b"}
In this case, it's unclear what the receiver of such a payload might do with it. Granted, it's also a problem that can usually be avoided w/more judicious use of struct tags.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ugorji/go/issues/159#issuecomment-225157837, or mute the thread https://github.com/notifications/unsubscribe/ABKlwi80wOyBEWM95IaUp4-PHaWAixnvks5qKUkygaJpZM4IyhSG .
When encoding structs w/embedded structs, shadowed fields aren't getting encoded. Unfortunately, this occurs even when the fields' encoded names are changed via struct tags.
In this case, the stdlib encoder encodes both values but the codec encoder only encodes the non-embedded value of the Composite struct.
Not sure if this is a bug, or just a difference between encoders.