I’m trying to deserialize a JSON string (from a http request body) into a protobuf object in Java using the com.google.protobuf.util.JsonFormat class:
JsonFormat.parser().ignoringUnknownFields().merge(new InputStreamReader(requestBody), builder);
The problem is that I’m using an existing protobuf message definition where some fields have been defined as bool
while the JSON I’m receiving has these fields as either 0
or 1
. When trying to deserialize, this results in exception with the following message: Invalid bool value: 1
.
Is there any way to cast 1
and 0
to true
and false
for a field that has the bool
type in the protobuf message definition type when deserializing?