night-config
night-config copied to clipboard
ObjectConverter for TOML with null-support
Sorry for flooding - I'm just discovering lots of cool features... ;-)
I have tried this example, which works perfectly fine - until I make it write to TOML, which doesn't support null-values (which is a restriction from it's spec). The problem for me is: what's the preferred way to handle a conversion if not every value is set and null may be valid? https://github.com/TheElectronWill/night-config/blob/78d9b1cbfc700bacddab903576693f7b89306a80/examples/src/main/java/ObjectConverterExample.java
Shouldn't it be possible to just skip null-values instead of raising Caused by: com.electronwill.nightconfig.core.io.WritingException: TOML doesn't support null values
? So conversion from null-containing object to config would just omit the nulled keys and vice versa (non-existing keys stay null).
No problem :-)
Not writing null values to the config would be great, I agree. That would make an interesting option for ObjectConverter
.
For now, you can:
- loop through the config and remove those entries yourself.
- use a
ConversionTable
to turn nulls into something else (like empty object, empty list, empty string, etc.)