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

Convert entities with ModelMapper

Source and destination entities have difference in style of field-naming (underscore in one, camelCase - in another). So, source: public class User { private String first_name; } Destination: public class UserDto { private String…
Jelly
  • 972
  • 1
  • 17
  • 40
2
votes
1 answer

Custom converter in ModelMapper not working

I have a converter that converts a double to a string. Before conversion, I want to format the double to a fix number of decimal place. But I noticed that it is not being invoked. Here is my method: The two models I have has the same attribute…
AKJ
  • 749
  • 6
  • 29
2
votes
1 answer

ModelMapper: apply rule to all fields of type

I have a DTO with a lot of String fields (some are of other types). When mapping objects into objects of another similar class, I need to apply a transformation to all fields of type String, in this case - trim(). So, I have: class MyDTO { String…
kit
  • 445
  • 2
  • 5
  • 19
2
votes
1 answer

How to use modelMapper to convert nested classes (Not equal classes)

I am new on backend side and I want to use modelmapper on my project. I know how can I use modelmapper on basic level. There is my Entity classes: public class Content { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name =…
Gokhan
  • 41
  • 4
2
votes
2 answers

The destination property matches multiple source property hierarchies - SpringBoot, ModelMapping

I am trying to add a list of rented books to my database. I am using ModelMaper with SpringBoot. Here is code: RentDto.java @Getter @Setter @EqualsAndHashCode @ToString @NoArgsConstructor public class RentDto { private Long rentId; private…
user9347049
  • 1,927
  • 3
  • 27
  • 66
2
votes
2 answers

Prevent circular reference with ModelMapper - List

I'm having a Json error because my DTO's are keeping a circular reference each other. CompanyDTO: @Data public class CompanyDTO { private Long id; private String name; private List companyCountries; //getters and…
2
votes
1 answer

Using ModelMapper on different data types with same attribute name

I have two classes say Animal & AnimalDto I want to use ModelMapper to convert Entity to DTO and vice verca. But the classes are supposed to have different data types for a few attributes having similar name. How do I achieve…
2
votes
1 answer

How can I perform findAllBy() using POST method?

I was asked to create a request that will list customers based on their genders. However the request method has to be POST and I was adviced to use a dto and a mapper to achieve this goal. I'll give some examples to further explain my problem. My…
2
votes
0 answers

How to add custom mappings in ModelMapper when target is a Protobuf Builder?

I am trying to map a source DTO to a protocol buffer object. However, the names of the fields in the source DTO do not match the names in the protocol buffer object, so I need to add custom mappings. I have seen two ways to do this, but both ways…
Alex A
  • 521
  • 1
  • 4
  • 16
2
votes
1 answer

How to configure ModelMapper to not set someClass=null when the values inside are null (someClass is a nested one)

first time posting here (and i hope you can understand my question and my english). I want to know if there is a way to "tell" ModelMapper to not set someClass=null when the values inside are null (in nested class). My problem is, when i call my…
2
votes
1 answer

ModelMapper Configuration error (failed to configure Mappings)

The problem i have right now is, that my configure method is throwing an exception saying that there is a configuration error, but i dont know what the problem is. Here is my configure method: public class ModelMapperEmb { public CasinoDto…
NyeSass
  • 373
  • 1
  • 4
  • 10
2
votes
1 answer

ModelMapper - simple way to flat an object

I have a source object with a structure like this: class SourceA { int www; SourceB sourceB; } class SourceB { int xxx; int yyy; int zzz; } And the destination: class Dest { int aaa; int bbb; int ccc; int ddd; } This is the most…
Vinicius
  • 1,060
  • 1
  • 12
  • 21
2
votes
1 answer

Tokenization in org.modelmapper

I am trying to find out why the JSON objects that I pass to a Spring controller get accepted with an extra field and when they don't get accepted. I was looking at the Modelmapper configuration in the documentation and came across this text for…
tehbobshow
  • 47
  • 1
  • 6
2
votes
0 answers

ModelMapper: Map object which has nested collection to flat object

I have a class with a nested list and I want to map this object into list of flat objects using ModelMapper. public class A { private String str; private String str2; private List blist; // Setters and getters } public class B { …
Sara Selim
  • 409
  • 5
  • 21
2
votes
1 answer

Use ModelMapper to flatten to list of ids

I am trying to use ModelMapper to map a collection of sub-objects to a list of id numbers. public class Child { private int id; private String childName; } public class Parent { private Set children; private String…
rboarman
  • 8,248
  • 8
  • 57
  • 87