Categories
Mastering Development

List mapping of two different beans using MapStruct

How can I do the bean mapping using MapStruct for the below scenario.
The entitlements property in both the classes is another bean with their own enum values.

@Mappings({
        @Mapping(target = "email", source = "entity.email"),
        @Mapping(target = "displayName", source = "entity.displayName"),
        @Mapping(target = "entitlements", source = "entity.entitlements")
})
UserRequest userBeanToUserRequest(UserBean entity);


class UserRequest {
     private EmailAddress email;
     private String displayName;
     private List<EntitlementBean> entitlements;
}

class EntitlementBean {
     private EntitlementBean.EntitlementState entitlementState;
     private Map<String, String> properties;

     public static enum EntitlementState {
         ACTIVE,
         INACTIVE;
     }
}

class UserRequest {
     private EmailAddress email;
     private String displayName;
     private List<EntitlementRequest> entitlements;
}

class EntitlementRequest {
     private EntitlementRequest.EntitlementState entitlementState;
     private Map<String, String> properties;

     public static enum EntitlementState {
         ACTIVE,
         INACTIVE;
     }
}

Leave a Reply

Your email address will not be published. Required fields are marked *