Сопоставитель MapStruct не правильно отображает вложенные DTO при весенней загрузкеJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Сопоставитель MapStruct не правильно отображает вложенные DTO при весенней загрузке

Сообщение Anonymous »

У меня есть DTO, который не работает с сопоставлением

Код: Выделить всё

    @Data
public class IndividualDTO {
private String passportNumber;
private String phoneNumber;
private UserDTO user;

@Data
public static class UserDTO {

@NotBlank
@Email
private String email;
private String secretKey;
private String firstName;
private String lastName;
private AddressDTO address;
}

@Data
public static class AddressDTO {
private String address;
private String city;
private String state;
private String zipCode;
private CountryDTO country;
}

@Data
public static class CountryDTO{
private String name;
}
}
Я пытаюсь построить карту с помощью MapStruct таким способом

IndividualMapper

Код: Выделить всё

@Mapper(componentModel = "spring", uses = {UserMapper.class, AddressMapper.class, CountryMapper.class})
public interface IndividualMapper {

IndividualMapper INSTANCE = Mappers.getMapper(IndividualMapper.class);

Individual toEntity(IndividualDTO dto);

IndividualDTO toDto(Individual entity);
}
AddressMapper

Код: Выделить всё

@Mapper(componentModel = "spring")
public interface AddressMapper {

Address toAddressEntity(IndividualDTO.AddressDTO addressDTO);

IndividualDTO.AddressDTO toAddressDto(Address address);
}
< /code>

 countrymapper < /strong> < /p>
< /blockquote>
@Mapper(componentModel = "spring")
public interface CountryMapper {

Country toCountryEntity(IndividualDTO.CountryDTO countryDTO);

IndividualDTO.CountryDTO toCountryDto(Country country);
}
< /code>

 usermapper < /strong> < /p>
< /blockquote>
@Mapper(componentModel = "spring")
public interface UserMapper {

User toUserEntity(IndividualDTO.UserDTO userDTO);

IndividualDTO.UserDTO toUserDto(User user);
}
В результате я получаю:

Код: Выделить всё

@Component
public class IndividualMapperImpl implements IndividualMapper {

@Override
public Individual toEntity(IndividualDTO dto) {
if ( dto == null ) {
return null;
}

Individual individual = new Individual();

return individual;
}

@Override
public IndividualDTO toDto(Individual entity) {
if ( entity == null ) {
return null;
}

IndividualDTO individualDTO = new IndividualDTO();

return individualDTO;
}
}
Согласно документации Mapstruct, все должно работать, но, к сожалению, я столкнулся с этой проблемой. > класс для меня, у которого нет логики

Подробнее здесь: https://stackoverflow.com/questions/793 ... pring-boot
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»