I'm generating Java bindings from Protobuf 3 schema definitions that 
include optional values represented with protobuf wrapper types. 

Decoding the fields as Java Optional<T> would work nicely if the generated 
accessors would be able to return null when the optional value is missing:

Optional.ofNullable(myObject.getMyField())

Unfortunately, the generated accessor returns the value or a default value, 
if missing.
So, one needs to resort to something like this:

myObject.hasMyField() ? Optional.of(myObject.getMyField()) : 
Optional.empty()

What's the best practice for handling this with Protobuf?

Is there a way to get protoc to generate code that would allow getting the 
actual underlying real value directly?

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/0c511624-7136-4e07-9fd4-3a439221f8b3n%40googlegroups.com.

Reply via email to