orika-mapper / orika

Simpler, better and faster Java bean mapping framework
http://orika-mapper.github.io/orika-docs/
Apache License 2.0
1.29k stars 268 forks source link

Mapping Member inner class from another simple class not working #394

Open wija-2015 opened 1 year ago

wija-2015 commented 1 year ago

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'.