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?