Skip to content

romankh3/spring-boot-mapstruct-example

Repository files navigation

SpringBoot Mapstruct testing example

Overview

Project can be used as an example of how to add Mapstruct to the project and how can be used.

Next, Project for demonstrating how can be added unit tests for Mapstruct Mappers with SpringBoot. Also, it is used to show the problems in testing mappers with SpringBootTest in post

In general, we can see, how Mapstruct can help us to map complicated POJOs, here we have next POJO:

public class StudentDTO {
    private Long id;
    private String name;
    private List<LectureDTO> lectures;
    private List<LecturerDTO> lecturers;
}

// with LectureDTO
public class LectureDTO {
    private Long id;
    private String name;
}
//and LecturerDTO
public class LecturerDTO {
    private Long id;
    private String name;
}

Mapstruct helps us to map it to models and back without creating a lot of code for it.

public class StudentModel {
    private Long id;
    private String name;
    private List<LectureModel> lectures;
    private List<LecturerModel> lecturers;
}

//with LectureModel
public class LectureModel {
    private Long id;
    private String name;
}

//and LecturerModel
public class LecturerModel {
    private Long id;
    private String name;
}

Building

mvn clean package

Troubleshooting

...

Release Notes

Please, follow RELEASE_NOTES.

Authors

Acknowledgments

...

Contributing

Please, follow Contributing page.

Code of Conduct

Please, follow Code of Conduct page.

License

This project is Apache License 2.0 - see the LICENSE file for details

About

Demo project for showing Mapstruct in general and unit tests in particularly

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages