sksamuel / hoplite

A boilerplate-free Kotlin config library for loading configuration files as data classes
Apache License 2.0
924 stars 74 forks source link

data class default values don't apply after resolvers #460

Open pschichtel opened 3 weeks ago

pschichtel commented 3 weeks ago

I just attempted to upgrade our hoplite setup 2.7.5 to 2.8.2. Part of that is the migration from preprocessors to resolvers, which seemed fairly straight forward. We had one processor that replaces ${...} variables and one that removes null-valued fields from map values.

The env preprocessor can produce null values in cases, where the environment variable is not set, so the second preprocessor's job is to get rid of these fields completely. This was necessary to get kotlin's data class parameter default values working.

Porting the preprocessors 1:1 over to the resolver API was as simple as replacing the process method signature with the resolve signature and fixing some recursive calls, but the problem now is, that non-null optional fields in data classes fail to decode, because it receives a null value.

So my issue is: How can I implement a resolver that produces null/undefined values that are then correctly mapped to parameter default values?