ModelMapper не преобразует дженерики должным образом ⇐ JAVA
-
Anonymous
ModelMapper не преобразует дженерики должным образом
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
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
Мобильная версия