DazzleConf
DazzleConf copied to clipboard
Optionals let you leave out keys
Title: If you have an Optional annotated as a config value, not including a key for the value will simply make the Optional return empty.
A configuration with
@ConfigKey("some.key")
Optional<Integer> lol();
some:
otherKey: otherValue
# note the lack of some.key
should load lol() as an empty opt
Ye but how the config gonna look if its not there
don't think yaml would accept null
What do you mean how would the config look if it were not there, there would simply not be a key entry. some.otherKey is not the same as some.key
Oh i got it, i think this should be added it would allow more abilities to do with the library
Not sure if this is supported but i'd pay/donate/support to have this implemented by either the repo maintainer or by someone else
I dont think that this suggestion respects one of the main ideas of library - no nullability. https://github.com/A248/DazzleConf/blob/master/docs/MainIdeas.md
@m4nya raised a good point. I've always avoided null values because the concept of null is ambiguous.
It's usually a bad idea to instruct users to leave a configuration option 'blank'. An empty string and a null value would be treated differently, but from the perspective of a user who knows nothing of Java, this would be quite the surprise.
Instead, I recommend using a configuration section which contains an "enable" boolean option:
some:
otherKey:
enabled: true
value: 'hello'
If you really needed Optional in your code, you could then use a default method which returns an Optional:
default Optional<String> optValue() {
return enable() ? Optional.of(value()) : Optional.empty();
}