Closed pw-lehre closed 1 year ago
I like the idea. If I'm not mistaken, we wouldn't even need a special annotation. Any method with @InheritInverseConfiguration
that matches the type parameters as inverting the Converter
declaration can already lead to generating this new Inverted Mapper class.
If it works automatically without further configuration, that would be even better.
As a stopgap solution, I'm currently using Spring magic to register @InheritInverseConfiguration-annotated methods in the Spring converter registry. But those methods aren't in the ConversionServiceAdapter, i.e. other Mappers cannot discover and use the inverse mappers. In short, solving this properly in maptruct would help here.
Outline:
@InheritInverseConfiguration
whose signature is the exact opposite of the Converter
type declaration will lead to the generation of an InvertedMapper
class outlined above.@pw-lehre I've done an implementation in this branch. While I'm still polishing some of the edges (including documentation), please feel free to have a go at it and check whether this looks like what you've got in mind.
In the end, I went for requiring an additional annotation @DelegatingConverter
which will generate a full class similar to your example. This new annotation can even be used without @InheritInverseConfiguration
, although I can't see a use case for that.
@Chessray Thanks a lot for the implementation, I did not expect that so many changes would be required for this. I'll try it out.
Hi everyone,
I'd like to define multiple Spring Converter<S, T> implementations (with different generic parameters) in a single @Mapper annotated interface. However, due to type erasure, it is currently not possible to directly declare the same interface multiple times.
Would it be possible to generate additional implementation classes that delegate back to the additional Mapping methods? Currently, we need to manually define a delegate mapper.
Current approach:
It would be nice if additional Implementation classes could be generated with a simple annotation such as e.g.
@GenerateDelegate
.Idea for a future approach:
I'm asking this here since it would be especially useful together with the Spring Converter Interface, and would potentially also require an entry in the ConversionServiceAdapter.