Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wija-2015 opened this issue Jan 31, 2023 · 0 comments
Open

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

wija-2015 opened this issue Jan 31, 2023 · 0 comments

Comments

@wija-2015
Copy link

wija-2015 commented Jan 31, 2023

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'.
@wija-2015 wija-2015 changed the title Mapping Member inner class from another simple class Mapping Member inner class from another simple class not working Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant