mapstruct-spi-protobuf
mapstruct-spi-protobuf copied to clipboard
176 mappers should never return null
Here's the code that implements the ban of null return values from mappers.
- null return values from domain->proto mapper will end up with a NPE thrown by Protobuff.
- null return values from proto->domain is less dangerous but it is best to let the application decide what to do in a post-mapper step.
The changes consist of systematically return a "default' value: empty string or arrays, EPOCH, zero, or protobuff's getDefaultInstance.
Close #176
@zartc Sorry for the late response,
I agree with your reasoning. On the proto->domain side I would like to see 2 different implementations, yours (map to empty domain) as well as the existing one (map to null).
If we split the existing mapper class into 3 variants
- DomainToProto
- ProtoToEmptyDomain
- ProtoToNullDomain
the developer can select the appropriate implementation based on his/her needs. It also avoid breaking (runtime) any existing use of this library (mapper uses attribute must be updated, but this is detected compile time)
Any news?