user2509940
user2509940

Reputation: 43

jhipster mapstruc relations

Hi I have a model in Jhipster with DTO mapstruct but I can´t correct mapping these relations

Person
   -String name
   -...
   Address address

Adress
    -String street
    -String zipCode

the generator create the DTO with no relations

PersonDTO
   -String name
   -...
   (lack of relation adress)

Then I modified my PersonDTO to include Adress like this:

PersonDTO
   -String name
   -...
   **-Address address;**

when comile the app I have these error:

  error: Can't map property "com.kalitron.cxc.web.rest.dto.AddressDTO address"
 to "com.kalitro
    n.cxc.domain.Address address". 
Consider to declare/implement a mapping method: "
com.kalitron.cxc.domain.Address map(com.kalitron.cxc.web.rest.dto.AddressDTO value)".
        Person personDTOToPerson(PersonDTO personDTO);
                ^

but i dont know how to correct config in the PersonMapper Interface.

Thanks in advance!

Upvotes: 0

Views: 1218

Answers (2)

nDijax
nDijax

Reputation: 521

Like Gunnar says you must declare a method And if you want to use the AddressMapper you can inject it:

@Inject
AddressMapper addressMapper;

And use it in method:

Address addressDtoToAddress(AddressDTO addressDto) {
    addressMapper.addressDTOtoAddress(addressDTO);
}

Upvotes: 0

Gunnar
Gunnar

Reputation: 19020

MapStruct does not know how to map the PersonDto property "address" of type AddressDto into a Address to be set into the resulting Person. As the error message is saying, declare a method

Address addressDtoToAddress(AddressDTO addressDto)

on your mapper, applying any configuration through @Mapping etc. it may need. The generated personDTOToPerson() implementation will then invoke this method for mapping the "address" property.

Upvotes: 1

Related Questions