Closed alfonz19 closed 6 years ago
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.
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.
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?
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.
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.
Is there any interest in this feature?
Ach! Sorry for not responding, I overlooked the mail.
There is interest, indeed. Tests seems nice, I fetch your changes and tests them in our project, and will be in touch (for some reason, clone does not work here right now).
And I will be sooner in touch. Thanks!
Martin.
po 5. 11. 2018 v 15:00 odesílatel Christopher Schütte < notifications@github.com> napsal:
Is there any interest?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/remondis-it/remap/issues/66#issuecomment-435884571, or mute the thread https://github.com/notifications/unsubscribe-auth/AJNSxNfHyoAA-4EGmY48jH0BOoMqatUZks5usER6gaJpZM4X1cLU .
Ok, I can confirm, that your changes work for us.
Thanks!
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.
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.