I want to create unit test that handle an exception when dto fields != entity fields. And print missing and extra fields. Is it possible to make it with MapStruct?
Simple example without annotations and boilerplate code. I have
public class TestDto {
long id;
String name;
int age;
long customerId;
String phone;
}
And Entity
public class TestEntity {
long id;
String name;
int age;
Customer customer;
String address;
}
@Mapping(source = "person.id", target = "personId") // in my Mapper class
TestDto toDto(Test entity);
output: Missing fields for dto. Please add!: address; Extra fields for dto. Please remove! : phone;
I tried to use reflection and it didn't work. https://stackoverflow.com/questions/75082277/how-to-find-all-missing-and-extra-fields-in-dto-by-their-entity-using-reflec?noredirect=1#comment132500771_75082277
I'd love to hear any ideas on how to do this.