Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: type mapping #1

Open
rocketraman opened this issue Jan 19, 2023 · 3 comments
Open

Feature request: type mapping #1

rocketraman opened this issue Jan 19, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@rocketraman
Copy link

Looks interesting and a great start.

Often times domain objects at different layers of an application have different types. For example, an internal domain object might use a different id type than an API or database model type.

Are you planning to provide any capability to map these types by allowing users to inject functions to do type mapping?

@YanneckReiss
Copy link
Owner

Thanks for your interest @rocketraman ! That is a very cool idea. I haven't thought about it yet tbh. But I can definitely see the use case for it.

What would be a convenient way for you to define such a function when you think about Kotlin projects you are working on?

I could think of some kind of adapter like we know from serialization libraries like Gson, Jackson etc, where we provide such a function to e.g. convert String --> UUID and vice versa. If the plugin finds a matching property name but the type doesn't match, it could look for a matching conversion function provided by the user and automatically add it to the final mapper function instead of the direct property reference.

@SamihMustafa
Copy link

+1 for this feature. Sometimes our classes have inner data classes that need to mapped as well. you can add its own KconMapper for the type but TestRepo is unable to map that type

data class TestRemote(
    var uid: String? = null,
    var name: String? = null,
    var location: LocationRemote? = null
)

data class LocationRemote(
    var geohash: String,
    var lat: String,
    var long: String
)


@KConMapper(fromClasses = [TestRemote::class], toClasses = [TestRemote::class])
data class TestRepo(
    @KConMapperProperty(["uid"])
    val userUid: String,
    @KConMapperProperty(["name"])
    val fullName: String,
    val location: LocationRepo? = null
)


@KConMapper(fromClasses = [LocationRemote::class], toClasses = [LocationRemote::class])
data class LocationRepo(
    var lat: String,
    var long: String
)

@rocketraman
Copy link
Author

Some prior art in java land might be worth reviewing. Maybe Kotlin can do better. :)

https://mapstruct.org/
https://modelmapper.org/

@YanneckReiss YanneckReiss added the enhancement New feature or request label Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants