night-config icon indicating copy to clipboard operation
night-config copied to clipboard

ObjectConverter for TOML with null-support

Open brainbytes42 opened this issue 2 years ago • 1 comments

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).

brainbytes42 avatar Jan 03 '23 14:01 brainbytes42

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.)

TheElectronWill avatar Jan 15 '23 11:01 TheElectronWill