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
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.
The text was updated successfully, but these errors were encountered:
thesamet
changed the title
TextFormat and JsonFormat ignores experimental proto3 optional enums
TextFormat and JsonFormat ignore experimental proto3 optional enums
May 8, 2020
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:
In code:
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 thatv
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.The text was updated successfully, but these errors were encountered: