-
Notifications
You must be signed in to change notification settings - Fork 101
Enforce setting of Optional fields #191
Comments
Hey! You can do this already if you like, for example:
does this accomplish what you need? |
The problem here is that Optional has two uses in Java: a) as safer 2016-09-13 9:44 GMT+01:00 James Baker [email protected]:
|
In other words, to not default Optional fields to empty. You can already do that manually by adding a missingX field, and overridding setX/merge/build to maintain it. In terms of adding explicit support to FreeBuilder, I would rather support general pluggable behaviour (issue #14) and have this be one plug-in we provide. Will leave this feature request open for voting. |
@ChrisAlice Can you elaborate on your missingX field workaround? I don't think I understand it. Thanks. |
so the simplest case would be something like (in the builder) something like:
which is pretty unpleasant (looking at JavaUtilOptionalSourceTest.java i'm not sure you need to do anything with merge). |
Yeah, that's not ideal, especially when we have multiple Optional fields on a class. I guess I'll wait for pluggable behavior, then. Thanks. |
You'll need to explicitly set isFavoriteColorSet in the mergeFrom(Builder) On Tue, 13 Sep 2016, 22:04 Paul Gross, [email protected] wrote:
|
What do you think about an option to force consumers of a builder to explicitly set optional fields. For example:
This would ensure that all attribute are accounted for, and prevent empty optionals from creeping in accidentally.
The text was updated successfully, but these errors were encountered: