Some Mapper {uses} won't get injected if there are many mappers in the uses clause #3915
Unanswered
juajuajuajuan
asked this question in
Q&A
Replies: 1 comment 1 reply
-
|
So I got inspired by the answer Tamim Ehsan gave in 3901 and changed default <T extends MiniDTOResponse> T createDTOwithExitsFalse(Class<T> dtoClass) {
try {
T dto = dtoClass.getDeclaredConstructor().newInstance();
dto.setExists(false);
return dto;
} catch (Exception e) {
throw new RuntimeException("Couldn't create DTO", e);
}
}to static <T extends MiniDTOResponse> T createDTOwithExitsFalse(Class<T> dtoClass) {
try {
T dto = dtoClass.getDeclaredConstructor().newInstance();
dto.setExists(false);
return dto;
} catch (Exception e) {
throw new RuntimeException("Couldn't create DTO", e);
}
}and now the Any hints? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have this
Both DoppingMapper and LockerMapper are basic mappers.
I'm using the GenericMapper because it allows me to use it generically for several mappers, as I'm looking for
{ "id": "39F47F8B83F5653CE0631F1EA8C0D44F", "home": { "id": "37C480A6E51A7BFBE0631F1EA8C0383C", "exists": true, "seats": 201, "lockers": 101, }, "away": { "id": null, "exists": false, "seats": 0, "lockers": 0, }, "dopping": { "id": "37C480A6E51A7BFBE0631F1EA8C0383C", "exists": true, "hasRestroom": true, "size": "25", } }instead of
{ "id": "39F47F8B83F5653CE0631F1EA8C0D44F", "home": { "id": "37C480A6E51A7BFBE0631F1EA8C0383C", "exists": true, "seats": 201, "lockers": 101, }, "away": null, ""dopping": { "id": "37C480A6E51A7BFBE0631F1EA8C0383C", "exists": true, "hasRestroom": true, "size": "25", } }and i can have the
@aftermappingin every mapper i need.But I'm getting this implementation
instead of expected
I've tried removing
DoppingMapperorLockerMapperin the {uses} and thenGenericMappergets injected, but when using all of them, it doesn't get, so I cannot do@Mapping(target = "home", source = "localRoom", defaultExpression = "java(genericMapper.createDTOwithExitsFalse(LockerDTOResponse.class))")as it wont findgenericMapper. If i modify the generated Impl and add it, program works as expected.Am I doing something wrong? Should i go with other approach?
At first i thought it may be because both DoppingMapper and LockerMapper were also declaring
uses = { GenericMapper.class}, but tried to remove it for testing and it's still happening.May it be because
and both Locker and Dopping extends BaseEntity?
In that case, how should i approach?
Beta Was this translation helpful? Give feedback.
All reactions