ModelMapper, mapping list of Entites to List of DTO objects

You can create util class: public class ObjectMapperUtils { private static final ModelMapper modelMapper; /** * Model mapper property setting are specified in the following block. * Default property matching strategy is set to Strict see {@link MatchingStrategies} * Custom mappings are added using {@link ModelMapper#addMappings(PropertyMap)} */ static { modelMapper = new ModelMapper(); modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); } … Read more

How to use ModelMapper for deep inheritance objects?

Possible solutions: Have you tried to add the attribute type in the parent class? This should be enough if you retrieve this field from the DB. A simple tested trick, add protected String type = this.getClass().getSimpleName().toLowerCase();. Notice that it must be protected. Here’s my tested code: @Data abstract class A { protected String type = … Read more

How to customize ModelMapper

First here are some links modelmapper getting started api doc blog post random code examples My impression of mm is that it is very well engineered. The code is solid and a pleasure to read. However, the documentation is very terse, with very few examples. Also the api is confusing because there seems to be … Read more

Better way to map Kotlin data objects to data objects

Simplest (best?): fun PersonForm.toPersonRecord() = PersonRecord( name = “$firstName $lastName”, age = age, tel = tel ) Reflection (not great performance): fun PersonForm.toPersonRecord() = with(PersonRecord::class.primaryConstructor!!) { val propertiesByName = PersonForm::class.memberProperties.associateBy { it.name } callBy(args = parameters.associate { parameter -> parameter to when (parameter.name) { “name” -> “$firstName $lastName” else -> propertiesByName[parameter.name]?.get(this@toPersonRecord) } }) } Cached … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)