Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapbackeds: Optionally enforce strictly all fields and/or default values #47

Open
kaifox opened this issue May 7, 2020 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@kaifox
Copy link
Member

kaifox commented May 7, 2020

As an option to the builder, one could imagine something like:

builder(Person.class).requireAllFields().....

A corresponding check in the builder (or constructor), could throw if not all fields are set during building time.

Or, if we allow nulls, we could at least prevent throwing because of the cast to primitives (which never can be null):

builder(Person.class).primitiveDefaults().... // would e.g. return 0 for int, 0.0 for double, 

One could even have more advanced default values something like:

builder(Person.class).defaultsWherePossible().... // would e.g. return (additionally to above) "" for string, empty lists for lists ... etc

Also something like

builder(Person.class).defaults(Function<Class<T>, T> defaultFactory).... 

could be imagined ...

All to be implemented as soon as we need it ;-)

@kaifox kaifox added the enhancement New feature or request label May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant