modelMapper.addMappings(new PropertyMap<Product, ProductDto>() {
@Override
protected void configure() {
skip().notes = null
skip().steps = null
/*or
skip().setNotes(null)
skip().setSteps(null)*/
}
})
Caused by ConfigurationException: ModelMapper configuration errors:
1) Error reading class <removed class name while pasting>
2) Failed to configure mappings
2 errors
->> 241 | throwConfigurationExceptionIfErrorsExist in org.modelmapper.internal.Errors
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 206 | build in org.modelmapper.internal.ExplicitMappingBuilder
| 72 | addMappings in org.modelmapper.internal.TypeMapImpl
| 110 | getOrCreate in org.modelmapper.internal.TypeMapStore
| 93 | addMappings in org.modelmapper.ModelMapper
| 79 | initializeModelMapper in <removed class name while pasting>
| 50 | init . . in ''
| 28 | doCall in BootStrap$_closure1
| 327 | evaluateEnvironmentSpecificBlock in grails.util.Environment
| 320 | executeForEnvironment in ''
| 296 | executeForCurrentEnvironment in ''
| 262 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . in java.lang.Thread
Caused by NullPointerException: null
->> 236 | validateVisitedMappings in org.modelmapper.internal.ExplicitMappingBuilder
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 227 | visitPropertyMap in ''
| 380 | configure in org.modelmapper.PropertyMap
| 194 | build in org.modelmapper.internal.ExplicitMappingBuilder
| 72 | addMappings in org.modelmapper.internal.TypeMapImpl
| 110 | getOrCreate in org.modelmapper.internal.TypeMapStore
| 93 | addMappings in org.modelmapper.ModelMapper
| 79 | initializeModelMapper in <removed class name while pasting>
| 50 | init . . in ''
| 28 | doCall in BootStrap$_closure1
| 327 | evaluateEnvironmentSpecificBlock in grails.util.Environment
| 320 | executeForEnvironment in ''
| 296 | executeForCurrentEnvironment in ''
| 262 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . in java.lang.Thread
--
You received this message because you are subscribed to the Google Groups "modelmapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modelmapper...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
/**
* Creating a Mapper field skip condition
*
* @param skipFields list of string. For eg. ['notes', 'steps']
* @return {@link org.modelmapper.Condition}
*/
static Condition createSkipCondition(def skipFields) {
new Condition() {
boolean applies(MappingContext context) {
!(context.mapping.destinationProperties[0].name in skipFields)
}
}
}
private void createTypeMap(Class source, Class target, String typeMapName = null, def skipFields = null) {
if (skipFields && typeMapName) {
modelMapper.createTypeMap(source, target, typeMapName).propertyCondition = Helper.createSkipCondition(skipFields)
} else if (typeMapName) {
modelMapper.createTypeMap(source, target, typeMapName)
} else if (skipFields) {
modelMapper.createTypeMap(source, target).propertyCondition = Helper.createSkipCondition(skipFields)
} else {
modelMapper.createTypeMap(source, target)
}
}
/**
* Domain To DTO Mapping
*
* Note: Mapping is required only if you want multiple combination of fields while mapping.
* For Example-
* ------------
* Scenario:: Product ==> ProductDto
* Combinations:
* 1. Default is skip notes and steps always
* 2. Skip only notes
* 3. Skip only steps
* 4. All data - Don't skip at all
*/
createTypeMap(Product, ProductDto, null, ['notes', 'steps'])
createTypeMap(Product, ProductDto, PRODUCT_TO_DTO_NOTES, ['steps'])
createTypeMap(Product, ProductDto, PRODUCT_TO_DTO_STEPS, ['notes'])
createTypeMap(Product, ProductDto, PRODUCT_TO_DTO_NOTES_STEPS)