Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping nested object with mapstruct

i create mapping like below. How to map flat dto object properties like (street, city, etc) to nested address in domain object. When I try to I've got an error:

[ERROR] diagnostic: Unknown property "address.postalCode" in return type. @Mapping(source = "city", target = "address.city"),

@Mapper(componentModel = "spring", uses = {})
public interface CompanyMapper {
    @Mappings({
            @Mapping(source = "id", target = "id"),
            @Mapping(source = "street", target = "address.street"),
            @Mapping(source = "city", target = "address.city"),
            @Mapping(source = "postalCode", target = "address.postalCode"),
            @Mapping(source = "province", target = "address.province"),
    })
    DomainObject map(DtoObject dto);

And classes...

public class Address {
            private String street;
            private Integer streetNumber;
            private String city;
            private String postalCode;
            private String province;
            //getters and setters
    }
public class DomainObject {
        private String id;
        private Address address;
        //getters and setters
}

public class DtoObject {
        private String id;
        private String street;
        private String city;
        private String postalCode;
        private String province;
        //getters and setters
}
like image 819
Piotr Sobolewski Avatar asked Jun 13 '16 17:06

Piotr Sobolewski


1 Answers

Nesting on the target side as you are trying to use it is not supported yet. There's a feature request for this (issue #389), but we did not yet get to implementing this.

like image 96
Gunnar Avatar answered Sep 21 '22 01:09

Gunnar