Replies: 3 comments 4 replies
-
|
Feel free to work on it, here is the existing feature request: #2688 The suggested annotation there is |
Beta Was this translation helpful? Give feedback.
-
|
Ok, I'll rename the annotation and issue a pull request. Do I have to write the documentation also or it's better to leave it for afterwards - documentation maintainer? |
Beta Was this translation helpful? Give feedback.
-
|
Would it be possible to ease the filtering using a hypothetical Example: class ContactDTO{
String fullName;
AddressDTO address;
List<PhoneDTO> phones;
}
class AddressDTO{
String address;
String country;
}
class PhoneDTO{
String number;
String type;
}
interface ContactMapper{
ContactDTO map(ContactEntity contact);
@Condition
default <T> boolean shouldMapProperty(@TargetPropertyPath String propertyPath) {
// property on the root object
if("fullName".equals(propertyPath)){
return true;
}
// property on the nested AddressDTO object, specifying that of the nested 'address' field I just want to map the 'country' property
if("address.country".equals(propertyPath)) {
return true;
}
// property on the nested collection of PhoneDTO objects, specifying that - for first phone in the list, I just want to map the number)
if("phones[0].number".equals(propertyPath)) {
return true;
}
return false;
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, all!
Currently there is no option to do run-time filtering based on target property name.
This comes very handy when mapping larger object graphs from ORM frameworks, to block
unnecessary loading from database while reusing the mapping code.
I have implemented this feature with additional (
@TargetPropertyName) annotated parameter in conditional / presence check methods.I would like to make a pull request if this feature can be accepted.
For instance:
Or even more complex example with passed
@Contextmethod parameter where run-time decisions based on target property name could be made:And more interesting / real-life example where glob like pattern filtering could be applied:
Beta Was this translation helpful? Give feedback.
All reactions