The mapper cannot be applied when we have a member inner class (Address) inside MetaAddress:
I want to map com.x.Address to com.y.MetaAddress.Address :
package com.x;
@Getter
@Setter
public class Address{
private String id;
private Long streetNumber;
private String streetNumberComplement;
private String streetType;
private String streetName;
}
package com.y;
@Data
public class MetaAddress {
Address address;
long complementCount;
boolean isRaCallRecommended;
@Getter
@Setter
public class Address{
private String id;
private Long streetNumber;
private String streetNumberComplement;
private String streetType;
private String streetName;
}}
This is the mapper :
@Component
public class GenericMapper {
private final MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
public MetaAddress.Address convertAddressToDto(Address address){
mapperFactory.classMap(Address.class, MetaAddress.Address.class);
return mapperFactory.getMapperFacade().map(address, MetaAddress.Address.class);
}
}
The error received :
while attempting to generate ObjectFactory using constructor 'public com.y.MetaAddress$Address(com.y.MetaAddress)', an automatic mapping of the source type ('Address') to this constructor call could not be determined. Please register a custom ObjectFactory implementation which is able to create an instance of 'Address' from an instance of 'Address'.
The mapper cannot be applied when we have a member inner class (Address) inside MetaAddress:
I want to map com.x.Address to com.y.MetaAddress.Address :
This is the mapper :
The error received :