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

Type Adapters #76

Open
pablisco opened this issue Nov 3, 2022 · 4 comments
Open

Type Adapters #76

pablisco opened this issue Nov 3, 2022 · 4 comments

Comments

@pablisco
Copy link
Collaborator

pablisco commented Nov 3, 2022

When creating copy constructors it would be useful to have mappings between types that are no exactly the same.

For instance, the representation of a date on the network layer may be a string, but it may be a date on the domain.

We could define strategies to work with such conventions:

@TypeAdapter
fun String.toDate(): Date = ...
@serras
Copy link
Collaborator

serras commented Nov 3, 2022

Wouldn't this work by simply having a Date function which takes a String as argument? In a sense, our functions with the same name as the type we want to build are "adapter" between those types already. WDYT?

@pablisco
Copy link
Collaborator Author

pablisco commented Nov 3, 2022

Hmm, yeah that could be an interesting idea. My only worry is the look up time. And naming clashes, as there could be the same Date on multiple places. Although, I guess we can determine it by the return type too. And then we don't even need to name it the same. But that would add even more potential clashes.

Need to have a play around with this.

@dave08
Copy link

dave08 commented May 3, 2023

Does KopyKat already know how to use value class underlying values for copying? On the data layer we need value classes but, when sending the response, Jackson doesn't seem to know what to do with them... so we'd like to use KopyKat to map between them.

@serras
Copy link
Collaborator

serras commented May 9, 2023

In principle it should work out of the box, since value classes are just as any other class. If you find a specific case which is not covered, we're happy to look at it and add support for it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants