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

ability to define custom mappers #66

Closed
alfonz19 opened this issue Oct 23, 2018 · 9 comments
Closed

ability to define custom mappers #66

alfonz19 opened this issue Oct 23, 2018 · 9 comments
Milestone

Comments

@alfonz19
Copy link

I'm mapping generated AVRO file to say JPA entity. But generated AVRO has Strings as CharSequence, for which there is no Mapper for. OK, so we useMapper:

.useMapper(Mapping.from(CharSequence.class).to(String.class).mapper())

but ... that won't work, since there is not (reasonable) properties to map and string is immutable. So we need to be able to replace whole class to define such mapper. Currently I don't see such option.

@schuettec
Copy link
Contributor

schuettec commented Oct 25, 2018

Yes since ReMap is a Java Bean mapper it only works for properties. This restriction was chosen to make the mapper testable using the assert API of ReMap. If one could define a mapper CharSequence -> String that automatically applies to all field mappings maching this types, we should also extend the Assert API to expect that in tests.

Quite interesting idea - thank you for that. We will think about that.

@alfonz19
Copy link
Author

please try to come up with some solution, since if we talk about mapping avro to java TO, it means, that I have to replace every single field like:

.replace(…, …).with(AvroUtil::charSeqToString)

where:

public static String charSeqToString(CharSequence seq) {
return seq.toString();
}

because there is no mapper CharSequence->String, and I cannto declare one.

@schuettec
Copy link
Contributor

Just to get that right, the field names in your example are equal for the classes but they differ in the fact that the one has CharSequence and the other has String fields?

@alfonz19
Copy link
Author

right.
Meaning, in this mine example it's trivial, yet IIUC it does not have nice solution. It's like data type conversion, and this will open door for more problem solving, when whole object has to be somehow translated to another. And this can work even if those object don't follow javabean convention.

@schuettec
Copy link
Contributor

schuettec commented Oct 29, 2018

You may want to have a look at #70. Especially the test case com.remondis.remap.implicitMappings.customTypeConversions.CustomTypeConversionsTest
reflects what I would suggest as a solution for your issue.

@schuettec schuettec modified the milestones: 2.0.0 API fixes, 4.1.0 Oct 29, 2018
@schuettec
Copy link
Contributor

schuettec commented Nov 5, 2018

Is there any interest in this feature?

@alfonz19
Copy link
Author

alfonz19 commented Nov 6, 2018 via email

@alfonz19
Copy link
Author

alfonz19 commented Nov 6, 2018 via email

@schuettec
Copy link
Contributor

The pull request was merged and I released the version 4.1.0 a few minutes ago. It will be available through JCenter or Maven Central in a few hours.

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

No branches or pull requests

2 participants