Skip to content

Unexpected 0-th value enum JSON serialization  #235

@antongrbin

Description

@antongrbin

The testing message is defined as follows:

syntax = "proto2";

message MessageWithEnum {
    enum EnumType {
      FOO = 0;
      BAR = 1;
    }
    optional EnumType value = 1;
}

We observe the following serialization with pbandk:

Source message current JSON serialization expected JSON serialization
MessageWithEnum() {"value":null} {}
MessageWithEnum(value=FOO) {} {"value":"FOO"}
MessageWithEnum(value=BAR) {"value":"BAR"} OK!

The bug is reproduced in a unit test here:
#234

I know that proto2 doesn't really have a JSON spec defined, but other protobuf implementations (java, python, swift) would all behave as expected in this example.

In proto3, we observed the following serialization behavior:

Source message current JSON serialization expected JSON serialization
TestAllTypesProto3() {} OK!
TestAllTypesProto3(optionalNestedEnum = FOO) {} {"value":"FOO"}
TestAllTypesProto3(optionalNestedEnum = BAR) {"value":"BAR"} OK!
  1. Do you agree that the current behavior is unexpected?
  2. Would you be open for us contributing a fix for it?

Thank you for your time :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions