Spring / Spring gRPC Interview Questions
How do you handle optional vs unset primitive fields in proto3?
By default in proto3, a scalar field like int32 count = 1; cannot distinguish between 'the client never set this' and 'the client explicitly set it to zero' - both serialize to the same absent-on-the-wire representation, and the generated getter simply returns the default.
Two common solutions: declare the field with the optional keyword, which generates a companion hasCount() presence-check method; or use the well-known wrapper types (google.protobuf.Int32Value, StringValue, BoolValue, etc.), which wrap the primitive in a message so its presence is unambiguous by construction. The wrapper-type approach is common when a field genuinely needs nullable semantics throughout a Spring service's domain model.
More Related questions...