schema-registry icon indicating copy to clipboard operation
schema-registry copied to clipboard

`ProtobufConverter`: representing `oneof` fields as unions is inconsistent with other implementations

Open mdub opened this issue 1 year ago • 1 comments

When faced with a Protobuf schema that uses oneof fields, such as:

message SampleMessage {
  oneof test_oneof {
    string name = 4;
    SubMessage sub_message = 9;
  }
}

the ProtobufConverter generates a union struct. When the resulting SchemaAndValue is serialized, e.g. to JSON, the "oneof field" will be represented in the structure, e.g.

{
  "test_oneof": {
    "name": "Bob Dobbs"
  } 
}

This is inconsistent with most other implementations of Protobuf → JSON serialization, which do not "box" oneof field-sets in this way. For example, println(sampleMessage.toJson()) would typically yield simply:

{
  "name": "Bob Dobbs" 
}

mdub avatar Aug 22 '24 05:08 mdub

I'm wondering whether the "boxing" behaviour (i.e. generation of a union struct per oneof) could be made configurable, so that we could opt out.

mdub avatar Aug 22 '24 08:08 mdub

Hi @rayokota. I notice this issue has been closed, but your PR to fix it has not yet been merged. Any update on when it might be merged, and released?

mdub avatar Sep 09 '24 23:09 mdub

Sorry, closed prematurely, it will be merged toward the end of Sept

rayokota avatar Sep 11 '24 16:09 rayokota