scala-automapper icon indicating copy to clipboard operation
scala-automapper copied to clipboard

Automapper doesn't map Seq[SourceClass] to Seq[TargetClass] without any errors

Open glmars opened this issue 5 years ago • 3 comments

automap(Seq(SourceClass())).to[Seq[TargetClass]] === Seq.empty

glmars avatar Dec 18 '19 05:12 glmars

Thanks for reporting this, the Automapper currently expects a case class as an input rather than any type (Seqs, Maps, etc). I will definitely have a look into making it support this use case as well when I get the chance because, intuitively, it should.

For now, you could simply wrap the source and target sequences in a case class and automap that as a workaround:

case class SourceWrapper(sources: Seq[SourceClass])
case class TargetWrapper(targets: Seq[TargetClass])

automap(SourceWrapper(Seq(SourceClass()))).to[TargetWrapper]

Not the neatest solution, but please let me know if this works for you in the meantime!

bfil avatar Dec 19 '19 11:12 bfil

We have used a different workaround and we are happy with it :wink: :

Seq(SourceClass()).map(automap(_).to[TargetClass])

glmars avatar Dec 20 '19 12:12 glmars

Oh yeah, that would work too. 👍

bfil avatar Dec 23 '19 09:12 bfil