You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In enumToJsonInternal function, it appears that when an unknown value is encountered, the integer value is passed through as is.
functionenumToJsonInternal(desc: DescEnum,value: unknown,enumAsInteger: boolean,): string|number|null{if(typeofvalue!="number"){thrownewError(`cannot encode ${desc} to JSON: expected number, got ${formatVal(value)}`,);}if(desc.typeName=="google.protobuf.NullValue"){returnnull;}if(enumAsInteger){returnvalue;// << [[ here ]]}constval=desc.value[value]asDescEnumValue|undefined;returnval?.name??value;// if we don't know the enum value, just return the number << [[ here ]]}
According to protobuf buffers document, the default value for an enum can be used 0. How about adding an option to specify a default value for unknown enum values, or converting them to 0?
Thanks!
The text was updated successfully, but these errors were encountered:
Creating an instance of the message Example, and assigning the value 2 to the field foo is not an error. Serializing the message to JSON should yield {"foo": 2}, and parsing this JSON should yield a message with foo = 2.
This can be unexpected, but we cannot change this behavior because it would not be compatible with other Protobuf implementations.
Greetings!
In
enumToJsonInternal
function, it appears that when an unknown value is encountered, the integer value is passed through as is.According to protobuf buffers document, the default value for an enum can be used 0. How about adding an option to specify a default value for unknown enum values, or converting them to 0?
Thanks!
The text was updated successfully, but these errors were encountered: