engine
engine copied to clipboard
Issue with the json serialization
The serialization in json doesn't reproduce the same result in some cases.
json != marshal(unmarshal(json))
List of differences observed:
- If no hash is provided, while reserialized an empty hash appears
- If no configuration is provided, while reserialized, an empty configuration appears
func TestSerializeJSON(t *testing.T) {
data := "{\"sid\":\"test\",\"name\":\"test\",\"source\":\"test\"}"
var srv Service
require.NoError(t, json.Unmarshal([]byte(data), &srv))
res, err := json.Marshal(srv)
require.NoError(t, err)
require.Equal(t, data, string(res))
}
This test should be ok but unfortunately it doesn't
expected: "{\"sid\":\"test\",\"name\":\"test\",\"source\":\"test\"}"
actual : "{\"hash\":\"\",\"sid\":\"test\",\"name\":\"test\",\"configuration\":{},\"source\":\"test\"}"
I think that this might be a bug in gogo. It does not add omitempty
value in json tag for the generated field. Every other filed have that.
Note also that Service.Configuration is not a pointer, so it will be always marshaled to {}