Edgar Avuzi
02/22/2025, 1:05 AMAndreyVanDenHaag
02/22/2025, 7:18 AMStefan Koppier
02/22/2025, 8:34 AMSzymon Jeziorski
02/22/2025, 8:51 AMMapStruct
nor similar java libraries like ModelMapper
They're not safe, add compilation overhead, often cause reduced readability and I'm pretty all the time saved would be quickly lost on debugging and tracing issues.
With Kotlin, you have extension functions and named arguments which gives you all you need to create safe and readable mapping functions.
Want to map UserEntity
to UserDto
for example?
Just define something like below
fun UserEntity.toDto() = UserDto(
name = name, // simple mappings
lastLoginTime = logins.map { it.time }.max() // in-place computations
[all other named params]
)
That combined with IDE assistance (I've previously used this plugin, but it looks like it's now built-in to IDE with "Specify all arguments by name" quick action) makes the whole process painless and intuitive.
I've jumped in to projects which used MapStruct
and ModelMapper
because that's what devs previously used in Java.
In all cases moving to Kotlin extensions was a way to go and made life easier.
Yes, that technically adds some code, but believe me it's worth it.
Not only do you get compile time safety, but the code is easier to reason about (no hidden implicitness).
Besides, it actually makes mappings easier to maintain IMO - since that's normal Kotlin code, it's automatically included within IDE refactorings, plus feedback loop is much faster due to instant inspections, warnings etc.
I cannot judge on Kotlin-first solutions though as I never felt the need to try themEdgar Avuzi
02/22/2025, 8:52 AMStefan Koppier
02/22/2025, 8:56 AMStefan Koppier
02/22/2025, 8:57 AMStefan Koppier
02/22/2025, 8:59 AMEdgar Avuzi
02/22/2025, 9:00 AMEdgar Avuzi
02/22/2025, 9:01 AMEdgar Avuzi
02/22/2025, 9:02 AMEdgar Avuzi
02/22/2025, 9:08 AMSzymon Jeziorski
02/22/2025, 9:10 AMStefan Koppier
02/22/2025, 9:11 AMEdgar Avuzi
02/22/2025, 9:15 AMEdgar Avuzi
02/22/2025, 9:16 AMEdgar Avuzi
02/22/2025, 9:16 AMEdgar Avuzi
02/22/2025, 9:17 AMEdgar Avuzi
02/22/2025, 9:19 AMEdgar Avuzi
02/22/2025, 9:47 AMSzymon Jeziorski
02/22/2025, 10:19 AMEdgar Avuzi
02/22/2025, 10:23 AMEdgar Avuzi
02/22/2025, 10:53 AMArjan van Wieringen
02/23/2025, 1:58 PMEdgar Avuzi
02/23/2025, 2:12 PMArjan van Wieringen
02/23/2025, 2:28 PMEdgar Avuzi
02/23/2025, 2:33 PMEdgar Avuzi
02/23/2025, 2:34 PMEdgar Avuzi
02/23/2025, 2:47 PMArjan van Wieringen
02/23/2025, 2:52 PMEdgar Avuzi
02/23/2025, 2:58 PMEdgar Avuzi
02/23/2025, 2:59 PMArjan van Wieringen
02/23/2025, 2:59 PMEdgar Avuzi
02/23/2025, 3:00 PMArjan van Wieringen
02/23/2025, 3:00 PMEdgar Avuzi
02/23/2025, 3:00 PMArjan van Wieringen
02/23/2025, 3:00 PMEdgar Avuzi
02/23/2025, 3:00 PMArjan van Wieringen
02/23/2025, 3:01 PMArjan van Wieringen
02/23/2025, 3:01 PMArjan van Wieringen
02/23/2025, 3:02 PMEdgar Avuzi
02/23/2025, 3:03 PMArjan van Wieringen
02/23/2025, 3:04 PMEdgar Avuzi
02/23/2025, 3:04 PMArjan van Wieringen
02/23/2025, 3:05 PMArjan van Wieringen
02/23/2025, 3:07 PMEdgar Avuzi
02/23/2025, 3:09 PMArjan van Wieringen
02/23/2025, 3:10 PMEdgar Avuzi
02/23/2025, 3:11 PMArjan van Wieringen
02/23/2025, 3:12 PMJacob
02/23/2025, 4:59 PMJacob
02/23/2025, 5:03 PMEdgar Avuzi
02/23/2025, 5:07 PMEdgar Avuzi
02/23/2025, 5:10 PMEdgar Avuzi
02/23/2025, 5:16 PMOh and static functions are fine! If you don't need to inject configuration then there's no reason to put logic in a configurable bean. YAGNI. And if you ever do need it it's very easy to convert to a bean or make a bean that wraps a static function
That's exactly the thing that at least I do not know the future. I doubt there is a magician here in this chat as well. Whatever requirement can come in. Keeping the logic in the component autoenables you to implement the exact feature and not restructuring the code as enabler activity. It is time consuming to restructure things. Expesialy when the code is rigid
Edgar Avuzi
02/23/2025, 5:22 PMJacob
02/24/2025, 3:02 AM