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

ConversionTable for ObjectConverter - based on Target Type

Open brainbytes42 opened this issue 4 months ago • 2 comments

Hi,

I am trying to read my (TOML-)ConfigFile into an POJO using the ObjectConverter.

I have several Durations, for example, and other custom objects. Using the @Conversion-Annotation, I'm able to parse my file successfully.

My Question/Suggestion ist the following: As the ObjectConverter relies on Reflection to set the Fields, it should be possible to read the field's types - wouldn't it be nice, to provide a ConversionTable selecting the converter based on the POJO's field? Currently, as far as I understood, the ConversionTable is applied to all Strings (or what TOML-type is specified), so it wouldn't be possible to habe a path (string) and a Duration side by side (without annotating each non-string field separately). If the COnverter could select for all Duration- (or Whatever-)fields the Duration- (or Whatever-)Converter from the conversion table, one would have to provide the converter only once and the config POJO would be more clean.

Any thoughts on this? :-)

brainbytes42 avatar Feb 14 '24 13:02 brainbytes42

I can think of a nice way to do that: give a special conversion table to the ObjectConverter, taking into account the type (toml value type) and destination type (Java field type). WDYT?

TheElectronWill avatar Feb 25 '24 16:02 TheElectronWill

That would be cool 🙂

brainbytes42 avatar Feb 25 '24 18:02 brainbytes42