AuthMe/ConfigMe

Drop MapperLeafType in favor of PropertyType

ljacqu opened this issue · 1 comments

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:

  • Create an interface extending PropertyType with Class<?> getType()
  • Replace LeafValueHandler to take property types instead of mapper leaf types
  • Determine the appropriate property type with some predicate:
    • Simple Class-based ones can just reuse the #getType method on the extension
    • Other predicates might do other stuff with the TypeInformation (from Field or generic type)
    • Finally, it should be possible to have separate predicates for convert and toExportValue, though we expect that to be rarely ever needed

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