Problem
You can encounter this problem when you use org.modelmapper.ModelMapper library and class. In most cases the issue is that you don’t provide the Constructors and/or Getters and Setters for you class.
Type definition error: [simple type, class com.bigdataetl.model.dto.PersonDto]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class com.bigdataetl.model.dto.PersonDto and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.ArrayList[0])",
Solution with Lombok
Using Lombok if you use these three annotations, Lombok provides Constructors, Getters and Setters.
import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @Data @AllArgsConstructor @NoArgsConstructor public class PersonDto { private String id; private String name; private int age; }
Solution without Lombok
As you can see without Lombok you have to provide Constructors, Getters and Setters on your own. It’s not a convenient way. I encourage you to use Lombok in the future 🙂
public class PersonDto { private String id; private String name; private int age; public PersonDto(String id, String name, int age) { this.id = id; this.name = name; this.age = age; } public PersonDto() { } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } }
If you enjoyed this post please add the comment below or share this post on your Facebook, Twitter, LinkedIn or another social media webpage.
Thanks in advanced!