mercredi 1 juillet 2020

How to provide MapStruct Mapping annotation mapping meta data at runtime

We use MapStruct between a business-model and our ui-model. When a UI client wants to get sorted data, it can specify a field from the ui-model. Our MapStructParser can get the corresponding business-model field-name and create the needed Criteria to sort it.

Example:

public interface ModelMapping extends BridgeMapping<BusinessModel, UiModel> {
   @Mapping(source = "zip", target = "plz")
   UiModel modelToUiModel(BusinessModel model, @MappingTarget UiModel uiModel);
}

The Problem:
How to read the @Mapping(source = "zip", target = "plz") annotation and get the source and target value? The Mapping-Annotation has RetentionPolicy.CLASS, so it's not possible to access it via reflections.





Aucun commentaire:

Enregistrer un commentaire