ModelMapper не преобразует дженерики должным образомJAVA

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

Сообщение Anonymous »


I'm using ModelMapper to convert from my domain object to DTO.

@Getter @Setter class Pojo { private String a; } @Getter @Setter class PojoDto { private String a; } My controller returns Page and my service layer returns Page, so the controller converts it:

private final Type pageDtoType = new TypeToken() {}.getType(); Page f = this.modelMapper.map(pojos, this.pageDtoType); f IS populated, but its populated with Pojo's and not PojoDto.

In my code example above the Dto and Pojo are the same, but in my application, the Dto deletes a few fields.

Is ObjectMapper just doing type erasure here? Why? The Pojo and Dto are different.

NOTE: Page is an interface here. If I create a PageDto and make it a class, then it copies it over. Weird that it doesn't work with interfaces.


Источник: https://stackoverflow.com/questions/780 ... s-expected
Ответить

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

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

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

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

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