https://kotlinlang.org logo
#server
Title
# server
l

Laurent Thiebaud

03/05/2024, 11:14 AM
Another question, how to you folks map between your data classes, and the different layers of your code? Are you doing it manually, with extension functions maybe, or using a library like shapeshift ?
👐 1
K 1
g

Gastón Saillén

03/05/2024, 12:25 PM
If you mean from a local database or network , I just use
.map
😅 1
d

dave

03/05/2024, 12:44 PM
Does Shapeshift do immutable migrations (ie. calling the target constructor reflectively? The presence of
vars
and default values in the target class would seem a little worrying to me because if you forget a mapping then you'll possibly end up with invalid data in the target,
a

Andrew O'Hara

03/05/2024, 2:37 PM
I do it manually with
.toX
extension functions. I find that object mapping libraries are more trouble than they're worth. Even efficient ones that use code generation have issues like dealing with non-standard behavior or potentially obfuscating compiler errors.
☝️ 1
👍 10
s

Siddharth Shah

03/05/2024, 4:48 PM
Manual "data mappers" 😅
c

CLOVIS

03/06/2024, 4:27 PM
Manually as well.
m

Marcus Ilgner

03/14/2024, 1:09 PM
I've been meaning to take a closer look at Shapeshift for some time now. What I found a bit confusing was that, at least in the README, the mapping annotations are on the source class. It's quite counterintuitive to me to give the source class knowledge about what target class(es) it is going to be mapped into and what those look like. So right now, manually mappers as well 😅
l

Laurent Thiebaud

03/14/2024, 1:14 PM
annotations aren't mandatory, you can also create an external mappers (as they say, kotlin developers don't like the magic of annotations 😄 )