AuthMe / ConfigMe

A simple configuration management library for any Java project!
MIT License
37 stars 14 forks source link

Drop MapperLeafType in favor of PropertyType #370

Closed ljacqu closed 1 year ago

ljacqu commented 1 year ago

Continuation of #312—

PropertyType cannot be reused 100% as it is in the mapper because we need to know which property type is responsible for the type of the field we've encountered. This is also true for creating export values. However, it might be clearer for the mapper's LeafValueHandler to get property types associated with a class. We could even extend the PropertyType interface with a method that returns the Class<?> type for basic types and automatically create the conditions. Like this, a user only has to implement property type and can easily place it into leaf value handler. I think I never considered this earlier because we need to find the appropriate PropertyType/LeafType not just for converting to the target type, but also from the target type when we create the export value. But for most types it should be enough to do a type check on the field type or the object type to convert.

Rough idea:

ljacqu commented 1 year ago

I remember another problem now: a mapper leaf type needs to be told what is being converted to. I can't have a PropertyType that is responsible for all enums if it's not being told what the target enum type is :( Adding the target type to a method is not really elegant for PropertyType itself, and if we do add it, then it might as well decide whether the type can be handled by that instance -> voting to close this