Upgrade to Pro — share decks privately, control downloads, hide ads and more …

You need an AutoMapper, but you don't know it yet!

You need an AutoMapper, but you don't know it yet!

It is quite common for a developer to have to map data. In the long run, this kind of code is boring to write. Why not generate it automatically? This is the promise that AutoMapper tries to solve: generating the code needed to map one data to another (array, class, etc.)

Through this talk, we will first see the Symfony Serializer and how it works.

Then, we will discover how AutoMapper takes advantage of the Serializer ecosystem while revolutionizing the Normalizer concept by adding code generation, thus drastically boosting performance!

369bc00f6a4b6d8d8b7d82df901009c2?s=128

Baptiste Leduc

June 17, 2021
Tweet

Transcript

  1. You need an AutoMapper, but you don't know it yet!

    Baptiste Leduc Dev @JoliCode @Korbeil_
  2. symfony/serializer

  3. What does it do?

  4. Encoding

  5. Normalizing

  6. GetSetMethodNormalizer

  7. PropertyNormalizer

  8. ObjectNormalizer

  9. How the serializer uses them? Priorities: - GetSetMethodNormalizer: N/A -

    PropertyNormalizer: N/A - ObjectNormalizer: -1000
  10. Performance 📈

  11. jane-php/automapper

  12. - 2016 JSON Schema - 2016 OpenAPI 2 - 2019

    OpenAPI 3 - 2018 AutoMapper
  13. Inspiration / Motivation + PHP Reflection

  14. How does it work? Back to the Serializer

  15. How does it work? And the AutoMapper

  16. How does it work? Generated Mapper

  17. How to use it? 1/2

  18. How to use it? 2/2 Array Object Object Array Object

    Object is also possible !
  19. Performances

  20. Usage: soyuka/esql Custom SQL language that uses the AutoMapper as

    an object hydrator.
  21. Usage: jolicode/elastically Use the AutoMapper as default Normalizer for Elasticsearch

    output
  22. And what about the AutoMapper and Symfony ?

  23. Using AutoMapper bundle

  24. Using AutoMapper bundle On a Symfony application 1/2

  25. Using AutoMapper bundle On a Symfony application 2/2

  26. A new Symfony component ?

  27. Or improve the Serializer ? https://github.com/symfony/symfony/issues/30818 - decoupling features from

    AbstractObjectNormalizer - merge the 3 big normalizers in one - hard dependency on symfony/property-info and symfony/property-access component
  28. Thank you! 👋 Baptiste Leduc Dev @JoliCode @Korbeil_ https://github.com/janephp/janephp https://github.com/janephp/demo-automapper