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
3
votes
2 answers

How to update object fields from another object using Modelmapper

I am planning to write a method which use to update a MyObject object with not null fields of another MyObject object. private void updateMyObject(MyObject sourceObject, MyObject destinationObject) { ModelMapper mapper = new ModelMapper(); …
Akila
  • 187
  • 2
  • 9
3
votes
1 answer

How to handle conversion of a Set to a List with ModelMapper

I have the following classes: public class MyEntity { private Set other; } public class MyDTO { private List other; } I created two PropertyMaps (using ModelMapper), one for each conversion from and to DTO public…
Stefanos Kargas
  • 10,547
  • 22
  • 76
  • 101
3
votes
1 answer

Strange behavior of ModelMapper used in Spring with HibernateTemplate

I have really strange behavior of ModelMapper framework combined with Spring and Hibernate 4. And after 2 days of searching through SO I still a little bit confused and can't figure out the reason of such strange behavior. I have 3 classes: class…
4the3eam
  • 194
  • 1
  • 12
3
votes
1 answer

ModelMapper configuration

Am seeing behaviour I can't explain with ModelMapper whilst trying to map a boolean to char. (I have checked, and the problem isn't Lombok related). @Data @NoArgsConstructor @AllArgsConstructor public class Entity { private boolean instance; } @Data…
Andrew Eells
  • 735
  • 12
  • 30
3
votes
1 answer

ModelMapper changes generic type on runtime - weird behavior

I am facing a very strange behavior in Java. I got two different classes that has no hierarchical connection: Class Template (Type hierarchy is Object -> A -> B -> Template), and class TemplateDto (Object -> TemplateDto). I am using ModelMapper…
Eyal
  • 1,748
  • 2
  • 17
  • 31
3
votes
1 answer

ModelMapper mapping from multi flat object to hierarchy object

I have a situation, where I need to map multi objects (in a flat structure) into one object (an hierarchy object) in Java using ModelMapper. For example, class Person{ String name; int age; } class Address{ int streetSumber; String…
jasonfungsing
  • 1,625
  • 8
  • 22
  • 34
3
votes
2 answers

Skip field globally in ModelMapper

I am using ModelMApper to map objects from DTO to Impl - when deserializing the object. This is done in combination with JAxRS. When user makes a POST/PUT request I dont want the "id" to ever be mapped. I need to skip the "id" field for all the…
allegjdm93
  • 592
  • 6
  • 24
2
votes
1 answer

ModelMapper map value from Map

I am trying to get a grasp of ModelMapper for the following use case: class A { public String name; public Map translations; } class ATranslation { public String desc; public String content; } class DTO { …
SpazzMarticus
  • 1,218
  • 1
  • 20
  • 40
2
votes
0 answers

Mapping DTO inside DTO using ModelMapper

I have the next entities: @Entity @Data @EqualsAndHashCode(callSuper = true) public class Student extends BaseEntity { private String identifier; @NotNull @Embedded private UserInformation…
Andrei Gabor
  • 231
  • 1
  • 8
2
votes
0 answers

modelMapper returning null value instead of Local date time value

i am using model mapper library and i am facing with a problem -> it's returning null value only when it's date types, bellow is my code. @Component @RequiredArgsConstructor public class RedisUtil { private HashOperations
hongse
  • 43
  • 3
2
votes
2 answers

Mapping DTO an Entity, leave entity null if all your field is null

My entity is return fields null example: EntityTest{id=null, name=null} but I need that if all fields are null return EntityTest = null TestEntity @Entity @Table(name="TestEntity") public class TestEntity { @Id @Column(name="id") …
2
votes
2 answers

map() method from mocked ModelMapper returns null value

i'm struggling with some weird problem related with Mockito and JUnit 5 with Spring Boot application. Here is the fragment of my AccountServiceTest class: @ExtendWith(MockitoExtension.class) @Import(MapperConfig.class) class AccountServiceTest { …
TenDan
  • 41
  • 6
2
votes
0 answers

How to have my DTO only have the ids of the full objects i have linked to my normal class with a OneToMany annotation in Java

I basically have a Class A and a Class B where ClassA has many of ClassB, i use a OneToMany annotation to get a List of all the ClassB Objects that belong to a ClassA Object, now i want to convert the information in ClassA to a ClassA DTO but in the…
MagicMikko
  • 21
  • 3
2
votes
0 answers

Modelmapper skip a object field

I have four class public class A { private String field1; private String field2; private B b; // setter and getter } public class B { private String fieldB1; private String fieldB2; // setter and getter } public…
user3162140
  • 461
  • 1
  • 5
  • 15
2
votes
1 answer

How to tell map function of the MapperModel that specific filed should have specific value?

I use ModelMapper in my project to map between DTO classes and models. For example: public class UserDto { private String name; private String phone; private String email; } public class User { @Id private String id; …
Michael
  • 13,950
  • 57
  • 145
  • 288