protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Map unknown enum cases to the default case (0)

Open mpdifran opened this issue 4 years ago • 2 comments

What language does this apply to? This applies to Swift, generated using https://github.com/apple/swift-protobuf

Describe the problem you are trying to solve. The problem to solve is around decoding unknown enum cases from the JSON format. Currently an error is thrown when decoding a message that contains an enum case the client doesn't know about.

Describe the solution you'd like When the server returns a new enum case in JSON to a client using an old spec, the has... field should return false for the enum's field, and the enum should be the default case (0). I'm petitioning Swift-Protobuf to add support for this, but they mentioned they'd like to see it supported here first.

Describe alternatives you've considered The only alternative we would have is to never add new cases to enums, which would be very cumbersome to deal with.

Additional context Please see the related issue here: https://github.com/apple/swift-protobuf/issues/972

mpdifran avatar Apr 01 '20 15:04 mpdifran

To clarify, this issues isn't just with Swift, the question is a general question about how to handle enums evolving and the json encoding.

thomasvl avatar Apr 01 '20 18:04 thomasvl

@thomasvl could you please help on this issue?no one helps for a long time :joy:

SylarChen avatar Apr 10 '20 03:04 SylarChen

There is now a test case in the conformance suite that exercises this behavior. Implementations should ignore unknown enumerators if the "ignore unknown" option is enabled: https://github.com/protocolbuffers/protobuf/blob/2a28082df37c509f972ea2082f768384ec37776f/conformance/binary_json_conformance_suite.cc#L1767-L1770

haberman avatar Feb 02 '24 01:02 haberman