protobuf
protobuf copied to clipboard
jsonpb: fix EmitDefaults=false emitting zero-values
Previously when checking if a value was a zero value to determine if it should be elided when EmitDefaults was true, some types of values were not being correctly inspected and would thus be emitted even if they had their zero value.
For example, a message type with nullable=false would yield a reflect.Struct type, but the zero-value check did not have a case for structs, just pointers being nil, which would only catch nullable=true message fields. Similar missing cases affect customtype casts to array, and potentially other types as well.
This changes the zero-ness determination to use the same recursive logic as go1.13's reflect.Value.IsZero, though that logic is inlined here to maintain backwards compatibility with older go versions.