Skip to content

Need specification for how to parse unrecognized enums in JSON #7392

@srcreigh

Description

@srcreigh

I was forwarded to here by @tbkka over in the Swift protobuf library from this issue: apple/swift-protobuf#972

As it stands the JSON serialization option in the swift-protobuf library is unusable because when it sees an unrecognized enum value that has been serialized to a JSON string, it throws an exception. There is no option to ignore the unrecognized string enum value, the only behaviour that swift-protobuf offers is to throw an exception.

To me it is abundantly obvious that any protobuf library has to ignore information that was generated using a newer schema.

For example, if a new enum field is shipped on a proto with v12.5 of an iOS app but is totally ignored (maybe it's a new feature under a shared schema that is implemented on a web app and is not implemented on the mobile app for a while). Then when this field, which is totally ignored, gets a new enum value, the v12.5 version of the app breaks because the only thing this that swift-protobuf can do is throw an exception when it sees the unrecognized enum value.

Of course this scenario is the core problem that protocol buffers as a whole set out to solve.

Protocol buffers were designed to solve many of these problems:

(Of course an iOS app is not a server but it's the same thing as far as this is concerned because it participates in a distributed protocol.)

Could someone please provide a specification for what a protobuf library should do when it sees an unrecognized Enum value serialized in a JSON string?

I can't imagine that every other protobuf client that supports JSON serialized string enum values here crashes when it sees something unrecognized. Can someone point me to the behaviour of some of the other client libraries so that the folks over at swift-protobuf can have some precedence for how to handle this situation?

Thank you.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions