How to map JAXB elements annotated with @XMLSeeAlso using mapStruct?

痴心易碎 提交于 2019-12-01 13:57:05

It seems like you have 3 different problems.

  1. It seems what you are trying to achieve is for MapStruct to detect all possible implementations for Customer (or see @XmlSeeAlso) and use the method you need. This is not possible automatically in MapStruct. See #131 for an existing feature request.
  2. This should happen when you have not defined the property correct. MapStruct actually looks into the getters and setters only (not in the field). So if you getter is getAM then your @Mapping(target = "AMLLineOfBusiness", ignore = true)
  3. This is similar with this question. Maybe you can try Reusing mapping configurations

A possible solution for 1 would be you to an instance of on your side.

@Mapper
public interface CustomerMapper {
    PersonalCustomer personcalCustomerToPersonalCustomer(PersonalCustomer pc);

    default Customer customerToCustomer(Customer customer) {
        if (customer instanceOf PersonalCustomer) {
            return personalCustomerToPersonalCustomer((PersonalCustomer) pc);
        } else if (customer instanceOf BusinessCustomer) {
            return businessCustomerToBusinessCustomer((BusinessCustomer) pc);
        }
    }
}

The reason for such things is that MapStruct is an annotation processor so it generated code during compilation time. On the other side Dozer is working with runtime information. Dozer can get the class during runtime and pick the right method. MapStruct cannot deduce all the possible implementations.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!