get smart with mapstruct
play

Get smart with MapStruct Filip Hrisafov @filiphr Filip Hrisafov - PowerPoint PPT Presentation

Get smart with MapStruct Filip Hrisafov @filiphr Filip Hrisafov Project lead of MapStruct Platform architect at Flowable Open source engines (BPMN, CMMN, DMN) Contributor to various other open source projects


  1. Get smart with MapStruct Filip Hrisafov @filiphr

  2. Filip Hrisafov ● Project lead of MapStruct ● Platform architect at Flowable ○ Open source engines (BPMN, CMMN, DMN) ● Contributor to various other open source projects filip.hrisafov@gmail.com @filiphr JUG Zürich 2019 #MapStruct @filiphr

  3. The Problem ● Need to map between different models ○ View Model vs DB Model ○ 3rd party REST API vs DB Model ● Types are similar, but not quite the same Car CarDto - make: String - make: String - model: Model - model: String - numberOfSeats: int - seatCount: int - manufacturingDate: LocalDate - manufacturingDate: String - price: BigDecimal - price: double - category: Category - category: String JUG Zürich 2019 #MapStruct @filiphr

  4. Problem Solutions ● Manually ○ Boring code ○ Error prone (might miss a mapping for a new property) ● Reflection-based libraries ○ Lack of type safety ○ Performance penalty ○ Difficult debugging JUG Zürich 2019 #MapStruct @filiphr

  5. Introducing MapStruct ● Mappings defined as interfaces ● Mapping java code generated at compile time using annotation processor ● No reflection ● No runtime dependencies JUG Zürich 2019 #MapStruct @filiphr

  6. Performance https://github.com/arey/java-object-mapper-benchmark JUG Zürich 2019 #MapStruct @filiphr

  7. Installation ● Installation instructions - http://mapstruct.org/documentation/installation/ ● Maven example - https://github.com/mapstruct/mapstruct-examples/blob/master/mapstruct-fie ld-mapping ● Gradle example - https://github.com/mapstruct/mapstruct-examples/tree/master/mapstruct-on- gradle ● IDE Support - http://mapstruct.org/documentation/ide-support ○ Eclipse Plugin ○ IntelliJ Plugin JUG Zürich 2019 #MapStruct @filiphr

  8. Demo

  9. Advantages of code generation ● Type-safe ● Quick feedback loop ● Easy to debug ● Plain method calls -> very fast ● No runtime dependencies ● Works on CLI or in your IDE JUG Zürich 2019 #MapStruct @filiphr

  10. What else is there ● Collection mappings ● Update methods ● Custom naming strategies ● Configuration inheritance ○ Inverse methods ○ @MapperConfig JUG Zürich 2019 #MapStruct @filiphr

  11. Future work ● Make use of constructor arguments when instantiating mapping targets ● Annotation composition (meta annotations) ● Mapping from Object into Map JUG Zürich 2019 #MapStruct @filiphr

  12. Get smart with MapStruct ● Reference guide, API docs etc. - mapstruct.org/ ● Source code, IDE plugins, examples - https://github.com/mapstruct/ ● Demo from this presentation - https://github.com/filiphr/jug_switzerland_2019 ● Gitter channel - https://gitter.im/mapstruct/mapstruct-users ● Discussion group - https://groups.google.com/forum/#!forum/mapstruct-users ● Latest news @GetMapStruct or #MapStruct JUG Zürich 2019 #MapStruct @filiphr

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend