Open
Description
Version: v1.34.1
Hi, I've encountered interop problems with protojson encoding between different languages
The following code produces error in golang:
anyResult := &anypb.Any{}
data := []byte(`{"@type":"type.googleapis.com/google.protobuf.Empty"}`)
err = protojson.Unmarshal(data, anyResult)
fmt.Println(err)
Output:
proto: (line 1:53): missing "value" field
Yet, this snippet in Java:
@Test
void test() throws InvalidProtocolBufferException {
final var typeRegistry = TypeRegistry.newBuilder()
.add(Empty.getDescriptor())
.build();
final var protoMessageAny = Any.pack(Empty.getDefaultInstance());
final var jsonString = JsonFormat.printer()
.preservingProtoFieldNames()
.includingDefaultValueFields()
.omittingInsignificantWhitespace()
.usingTypeRegistry(typeRegistry)
.print(protoMessageAny);
System.out.println(jsonString);
}
produces output:
{"@type":"type.googleapis.com/google.protobuf.Empty"}
python, same thing:
from google.protobuf.any_pb2 import Any
from google.protobuf.empty_pb2 import Empty
from google.protobuf.json_format import MessageToJson
a = Any()
a.Pack(Empty())
print(MessageToJson(a))
Output:
{
"@type": "type.googleapis.com/google.protobuf.Empty"
}
It doesn't seem golang implementation should expect value
field