Search code examples
javascalaslickpojoorika

Mapping Scala Slick objects to/from Java POJOs


I'd like to use Scala Slick in my backend code and I also have requirement to support a legacy web service API that needs to expose my domain model as normal Java POJOs.

Are there some nice object mapper libraries or other solutions for this task other than writing manual mapping code? I have used Orika object mapper before (in Java only) and it has some nice features like mapping properties with the same name by default, ability to provide custom mappers by types..


Solution

  • You can use the extensible Slick code generator to generate mappings to your existing classes instead of new case classes. You probably would want to enable = false some of the inner classes of the code generator and override the EntityType to generate simple factories instead of case classes. See http://slick.typesafe.com/doc/2.0.2/code-generation.html

    I'll speak about the code generator at Scala Days 2014, which will probably be helpful with this question as well.