When jsonValue is called using the output of reflect.ValueOf() instead of reflect.StructField, any interface type is lost through re-packing to the empty interface (any). This means the reflect.Kind of a union field is no longer the union type, but instead its underlying concrete type. The current code doesn't handle this case, leading to runtime errors.
This handling code is now added, with a couple more fixes related to empty types.
Tested manually that the following ygnmi call is no longer affected by the original error:
coverage: 89.606% (-0.006%) from 89.612%
when pulling da103aae6762e45794aded15b7b391304c1c203e on marshal7951-union-bug
into dca67e299ee14893d2f9a55eaf61e6048a3c44cf on master.
When
jsonValue
is called using the output ofreflect.ValueOf()
instead ofreflect.StructField
, any interface type is lost through re-packing to the empty interface (any). This means thereflect.Kind
of a union field is no longer the union type, but instead its underlying concrete type. The current code doesn't handle this case, leading to runtime errors.This handling code is now added, with a couple more fixes related to
empty
types.Tested manually that the following ygnmi call is no longer affected by the original error: