You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TextFormat and JsonFormat ignore experimental proto3 optional enums #7480
What version of protobuf and what language are you using?
Version: 3.12.0-rc-1
Language: Java
What operating system (Linux, Windows, ...) and version?
Ubuntu 19.10
What runtime / compiler are you using (e.g., python version or gcc version)
openjdk version "1.8.0_252"
What did you do?
Steps to reproduce the behavior:
Define proto:
syntax = "proto3";
package mypkg;
enum V {
A = 0;
B = 1;
C = 2;
}
message Msg {
optional V v = 1;
}
In code:
import mypkg.Np.Msg;
import com.google.protobuf.TextFormat;
import com.google.protobuf.util.JsonFormat;
import java.lang.String;
public class Main {
public static void main(String[] args) throws Exception {
Msg withV = Msg.newBuilder().setV(mypkg.Np.V.B).build();
// prints false, excepted true
System.out.println(TextFormat.parse(withV.toString(), Msg.class).hasV());
String js = JsonFormat.printer().print(withV);
Msg.Builder b = Msg.newBuilder();
JsonFormat.parser().merge(js, b);
// prints false, excepted true
System.out.println(b.build().hasV());
}
}
Generated protos using protoc with --experimental_allow_proto3_optional.
What did you expect to see
When serializing the message withV above into ascii format or json, the optional field correctly shows up. The expectation is that v would be present when the json/ascii is parsed back.
What did you see instead?
However, when parsing both the json or text representation, the optional field gets ignored: hasV returns false in both cases, despite that the enum appears in the textual presentation.
changed the title [-]TextFormat and JsonFormat ignores experimental proto3 optional enums[/-][+]TextFormat and JsonFormat ignore experimental proto3 optional enums[/+]on May 8, 2020
Activity
[-]TextFormat and JsonFormat ignores experimental proto3 optional enums[/-][+]TextFormat and JsonFormat ignore experimental proto3 optional enums[/+]haberman commentedon May 10, 2020
Thank you for the report, and for trying out a prerelease version! I have a fix for this coming shortly. I will make sure it is in the 3.12.0 release.
Cherry-pick the fix to protocolbuffers#7480 from protocolbuffers#7485.
haberman commentedon May 13, 2020
The fix for this is released in https://github.com/protocolbuffers/protobuf/releases/tag/v3.12.0-rc2.