Module utility.producer
Class ValidatingModelMapper
java.lang.Object
org.modelmapper.ModelMapper
uk.co.jasonmarston.kiunzi.utility.producer.modelmapper.ValidatingModelMapper
public class ValidatingModelMapper
extends org.modelmapper.ModelMapper
A
ModelMapper extension that automatically validates the mapped destination
object using Bean Validation after every mapping operation.
If any constraint violations are found on the destination, a
DomainInvariantViolationException
is thrown instead of returning the partially-valid object.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionValidatingModelMapper(jakarta.validation.Validator validator) Constructs aValidatingModelMapperwith the given Bean ValidationValidator. -
Method Summary
Modifier and TypeMethodDescription<T> TMaps properties fromsourceto a new instance ofdestinationType, then validates the result against all declared Bean Validation constraints.<T> TMaps properties fromsourceto a new instance ofdestinationTypeusing the named type map, then validates the result.voidMaps properties fromsourceto an existingdestinationobject, then validates the destination against all declared Bean Validation constraints.voidMaps properties fromsourceto an existingdestinationobject using the named type map, then validates the destination object.<T> TMaps properties fromsourceto a new instance of the given genericdestinationType, then validates the result against all declared Bean Validation constraints.<T> TMaps properties fromsourceto a new instance of the given genericdestinationTypeusing the named type map, then validates the result.Methods inherited from class org.modelmapper.ModelMapper
addConverter, addConverter, addMappings, createTypeMap, createTypeMap, createTypeMap, createTypeMap, createTypeMap, createTypeMap, createTypeMap, createTypeMap, emptyTypeMap, emptyTypeMap, getConfiguration, getTypeMap, getTypeMap, getTypeMaps, registerModule, typeMap, typeMap, validate
-
Constructor Details
-
ValidatingModelMapper
public ValidatingModelMapper(jakarta.validation.Validator validator) Constructs aValidatingModelMapperwith the given Bean ValidationValidator.- Parameters:
validator- the JakartaValidatorused to validate mapped destinations; must not benull
-
-
Method Details
-
map
Maps properties fromsourceto an existingdestinationobject, then validates the destination against all declared Bean Validation constraints.- Overrides:
mapin classorg.modelmapper.ModelMapper- Parameters:
source- the source object to map from; must not benulldestination- the destination object to map into; must not benull- Throws:
uk.co.jasonmarston.kiunzi.utility.validator.DomainInvariantViolationException- if the destination object fails validation after mapping
-
map
Maps properties fromsourceto a new instance ofdestinationType, then validates the result against all declared Bean Validation constraints.- Overrides:
mapin classorg.modelmapper.ModelMapper- Type Parameters:
T- the destination type- Parameters:
source- the source object to map from; must not benulldestinationType- theClassof the destination type; must not benull- Returns:
- the validated mapped destination instance
- Throws:
uk.co.jasonmarston.kiunzi.utility.validator.DomainInvariantViolationException- if the destination object fails validation after mapping
-
map
Maps properties fromsourceto a new instance of the given genericdestinationType, then validates the result against all declared Bean Validation constraints.- Overrides:
mapin classorg.modelmapper.ModelMapper- Type Parameters:
T- the destination type- Parameters:
source- the source object to map from; must not benulldestinationType- theTypeof the destination; must not benull- Returns:
- the validated mapped destination instance
- Throws:
uk.co.jasonmarston.kiunzi.utility.validator.DomainInvariantViolationException- if the destination object fails validation after mapping
-
map
Maps properties fromsourceto an existingdestinationobject using the named type map, then validates the destination object.- Overrides:
mapin classorg.modelmapper.ModelMapper- Parameters:
source- the source object to map from; must not benulldestination- the destination object to map into; must not benulltypeMapName- the name of the type map to use; must not benull- Throws:
uk.co.jasonmarston.kiunzi.utility.validator.DomainInvariantViolationException- if the destination object fails validation after mapping
-
map
Maps properties fromsourceto a new instance ofdestinationTypeusing the named type map, then validates the result.- Overrides:
mapin classorg.modelmapper.ModelMapper- Type Parameters:
T- the destination type- Parameters:
source- the source object to map from; must not benulldestinationType- theClassof the destination type; must not benulltypeMapName- the name of the type map to use; must not benull- Returns:
- the validated mapped destination instance
- Throws:
uk.co.jasonmarston.kiunzi.utility.validator.DomainInvariantViolationException- if the destination object fails validation after mapping
-
map
Maps properties fromsourceto a new instance of the given genericdestinationTypeusing the named type map, then validates the result.- Overrides:
mapin classorg.modelmapper.ModelMapper- Type Parameters:
T- the destination type- Parameters:
source- the source object to map from; must not benulldestinationType- theTypeof the destination; must not benulltypeMapName- the name of the type map to use; must not benull- Returns:
- the validated mapped destination instance
- Throws:
uk.co.jasonmarston.kiunzi.utility.validator.DomainInvariantViolationException- if the destination object fails validation after mapping
-