Map me if you can! Painless bean mappings with MapStruct by Gunnar Morling

  Рет қаралды 34,443

Devoxx

Devoxx

6 жыл бұрын

The mapping between different data models is a common but unpleasant task for developers, e.g. when propagating data from an internal domain model to the elements of a REST facade, UI layer or external web service.
Writing conversion code by hand is tedious and error-prone, while reflection-based solutions suffer from poor performance and the lack of type-safety. MapStruct takes a fresh look at the issue and generates mapping code at compile time, based on Java interface definitions. The resulting code is type-safe and super-fast, has no dependencies and is easy to understand (and debug, if ever needed). Providing many type conversions out of the box, MapStruct also allows you to customize and amend mappings as needed.
We'll discuss typical mapping problems and their solution with MapStruct. You'll see the generator in action (CLI and Eclipse) and quickly forget about the pain bean mappings used to give you in the past.
Gunnar Morling is a software engineer and open-source enthusiast by heart. He’s leading the Debezium project, a tool for change data capture (CDC). As part of the Hibernate team, he contributes to Hibernate Search, OGM and Validator. Gunnar is the spec lead for Bean Validation 2.0 (JSR 380). In his spare time he leads the MapStruct project. Prior to joining Red Hat, he worked on a wide range of Java EE projects in the logistics and retail industries. He’s based in Hamburg, Germany.

Пікірлер: 20
@yuriyk8002
@yuriyk8002 3 жыл бұрын
That is just beautiful!
@charluz
@charluz Жыл бұрын
Excellent explanation, thank you.
@xxxxxxxxx2947
@xxxxxxxxx2947 2 жыл бұрын
Excellent Explanation...
@PatrickCornelien
@PatrickCornelien 6 жыл бұрын
This is quite a neat project, especially that it doesn't use reflection at runtime!
@zanelesibanyoni7951
@zanelesibanyoni7951 3 жыл бұрын
amazing example
@greengrer
@greengrer 2 жыл бұрын
Thank you, it explained a lot
@cosmicjava
@cosmicjava 4 ай бұрын
Nice 🎉
@ShaliniSharma21
@ShaliniSharma21 3 жыл бұрын
What about collection such as list, which has fetch type lazy, how to resolve lazy initialisation error How to map collection sources?
@nadimmansour9792
@nadimmansour9792 4 жыл бұрын
I need to map data using java from json file to an ontology created in proetege platform and its in rdf-xml format ? can this help ?
@peteabc1
@peteabc1 6 жыл бұрын
The code generation is nice, but I don't like the @Mapping annotation. It's like unsafe assignment done with annotation and field name as string, so what would happen, if I start to refactor? If only we could pass somethign like Class::variable, that'll be really great for this. Or maybe some kind of DSL, but there's also problem of fields visiblity..
@GunnarMorling
@GunnarMorling 6 жыл бұрын
If you refactored your mapped properties, you'd get an exception at compile time about referencing a non-existing property from within your @Mapping annotation, i.e. feedback is much faster than with reflection-based solutions. We also provide an IntelliJ plug-in (it's on the market place), which supports refactorings: if you change a mapped bean property, any references in @Mapping annotations will be adjusted as well. That's as good as it gets until true field/property references in annotations are part of the Java language (if that ever happens, who knows).
@ahmedmk534
@ahmedmk534 2 жыл бұрын
you ca use the IDE's plugins to solve refactoring issues
@handsome_man69
@handsome_man69 2 жыл бұрын
Handsome man
@Thematrixhackyou
@Thematrixhackyou 5 жыл бұрын
Can i Mapping a Absctract class ¿? can i Mapping a object with contains array of objects ¿?
@ythalorossy
@ythalorossy 5 жыл бұрын
Yes, for the second question, you can.
@ChristopherRockhill
@ChristopherRockhill 4 жыл бұрын
Ythalo Rossy Saldanha Lira example?
@user-wq3gw1lg6f
@user-wq3gw1lg6f 3 жыл бұрын
Why didnt u run the code???
[VDZ19] Get smart with MapStruct by Filip Hrisafov
19:55
1❤️#thankyou #shorts
00:21
あみか部
Рет қаралды 69 МЛН
Each found a feeling.#Short #Officer Rabbit #angel
00:17
兔子警官
Рет қаралды 6 МЛН
Countries Treat the Heart of Palestine #countryballs
00:13
CountryZ
Рет қаралды 22 МЛН
How to Best Use Java Records as DTOs in Spring Boot 3
11:26
JAVA DTO Pattern Tutorial | Simplify Your Code
19:12
Amigoscode
Рет қаралды 189 М.
How to Return DTOs from Native Queries with Spring Data JPA
7:02
Thorben Janssen
Рет қаралды 32 М.
JPA beyond copy paste by Jakub Kubrynski
49:02
Devoxx
Рет қаралды 21 М.
Kotlin for Java Programmers by Venkat Subramaniam
51:40
Devoxx
Рет қаралды 55 М.
Carregando telefone com carregador cortado
1:01
Andcarli
Рет қаралды 2,6 МЛН
i like you subscriber ♥️♥️ #trending #iphone #apple #iphonefold
0:14
Samsung S24 Ultra professional shooting kit #shorts
0:12
Photographer Army
Рет қаралды 9 МЛН
5 НЕЛЕГАЛЬНЫХ гаджетов, за которые вас посадят
0:59
Кибер Андерсон
Рет қаралды 1,5 МЛН