Questions tagged [modelmapper]

An intelligent object mapping framework that automatically maps objects to each other.

ModelMapper is an intelligent object mapping framework that automatically maps objects to each other. It uses a convention based approach to map objects while providing a simple refactoring safe API for handling specific use cases.

435 questions
107
votes
14 answers

Better way to map Kotlin data objects to data objects

I want to convert/map some "data" class objects to similar "data" class objects. For example, classes for web form to classes for database records. data class PersonForm( val firstName: String, val lastName: String, val age: Int, //…
sunnyone
  • 1,450
  • 2
  • 13
  • 13
32
votes
3 answers

How to use ModelMapper for deep inheritance objects?

A.java @Entity @Getter @Setter @Inheritance @JsonTypeInfo(use=JsonTypeInfo.Id.NAME, inclue=JsonTypeInfo.As.PROPERTY, property="type") @JsonSubTypes({ @JsonSubTypes.Type(value=AA.class,name="aa"), …
Morteza Malvandi
  • 1,656
  • 7
  • 30
  • 73
32
votes
5 answers

How to customize ModelMapper

I want to use ModelMapper to convert entity to DTO and back. Mostly it works, but how do I customize it. It has has so many options that it's hard to figure out where to start. What's best practice? I'll answer it myself below, but if another…
John Henckel
  • 10,274
  • 3
  • 79
  • 79
31
votes
5 answers

Does ModelMapper library support collections like ArrayList or HashSet?

This question is not relating with AutoMapper. My question is about ModelMapper in java, however I cannot create new tag for modelmapper as my little reputation. Sorry for confusion. Anyway, my question is that does modelmapper library support…
Ray
  • 4,038
  • 8
  • 36
  • 48
29
votes
5 answers

ModelMapper: matches multiple source property hierarchies

I cannot resolve modelMapper error. Do you have any ideas where is the issue? NB: In view java.sql.Time doesn't have non-argument constructor I didn't find the better way than to write converter org.modelmapper.ConfigurationException: ModelMapper…
Bizon4ik
  • 2,604
  • 4
  • 20
  • 46
27
votes
5 answers

ModelMapper, mapping list of Entites to List of DTO objects

I am writing simple blog web application using Spring MVC framework. I am willing to add DTO layer to my app. I decided to use ModelMapper framework for conversion from Entity objects to DTO objects used in my views. I have just one problem. On my…
Gromo
  • 360
  • 2
  • 4
  • 13
25
votes
3 answers

ModelMapper skip a field

I would like to map between UserDTO and User, but excluding one field, say city. How can I do that, cause I though that this approach would work, but it doesn't: ModelMapper modelMapper = new…
user3529850
  • 1,632
  • 5
  • 32
  • 51
21
votes
2 answers

How to use modelMapper to convert nested classes

I have a simple class that I want to map to a DTO class using modelMapper. class Source { private String name; private String address; List things; // getters and setters follows } class Thing { private String…
user497087
  • 1,561
  • 3
  • 24
  • 41
20
votes
2 answers

How to use Explicit Map with Java 8 and ModelMapper?

I learn how to use ModelMapper by official documentation http://modelmapper.org/getting-started/ There is code sample for explicit mapping using java 8 modelMapper.addMappings(mapper -> { mapper.map(src -> src.getBillingAddress().getStreet(), …
hudrogen
  • 342
  • 1
  • 3
  • 13
18
votes
2 answers

Difference between jackson objectMapper to others

I can't find any explanation about difference between jackson's ObjectMapper to other mappers like dozer/mapStruct/modelMapping/etc. All the articles compare dozer/mapStruct/modelMapping but they ignore ObjectMapper. I can't understand what is…
Plaggyy
  • 219
  • 1
  • 2
  • 8
14
votes
3 answers

Modelmapper to convert from String to LocalDate

My DTO is having date field in String format. My entity is having date as LocalDate. Currently I am skipping it from map and then later manually explicitly setting it (String to Date and vis-versa). is it possible to convert it automatically? I…
user2869612
  • 607
  • 2
  • 10
  • 32
13
votes
2 answers

How to map multiple fields into one destination field using modelmapper

How to map/merge multiple fields into one field? Like concatenate a firstname and lastname to the destination fullname? public class ModelMapperConfigTest { @Test public void should_validate() { new…
d0x
  • 11,040
  • 17
  • 69
  • 104
12
votes
2 answers

How can I use Java records as DTO with ModelMapper?

I'm refactoring my code. I want to use java records instead of java class in my DTO. To convert DTO to Entity, I'm using ModelMapper (version 2.3.5). When I try to get info about user (call method co convert Entity to DTO) I get this error. Failed…
Pawel
  • 427
  • 2
  • 7
  • 15
12
votes
3 answers

ModelMapper: Choose mapping based on Child class

TL;DR I want to use modelMapper in a way that I map from AbstractParent to AbstractParentDTO and later in the ModelMapper-Config call the specific mappers for each Sub-class and then skip the rest of the (abstrac-class) mappings. How is that…
Simon
  • 397
  • 1
  • 3
  • 24
12
votes
1 answer

ModelMapper: Ensure that method has zero parameters and does not return void

I have the following configuration for the model mapper to convert an instance of User class to an instance of ExtendedGetUserDto. public ExtendedGetUserDto convertToExtendedDto(User user) { PropertyMap userMap…
Arian
  • 7,397
  • 21
  • 89
  • 177
1
2 3
28 29