In Android app, we use java reflection, in this discussion any tool for java object to object mapping?, it’s seen lots of library can chose on, but to use in Android, I have tried Commons-BeanUtils, Dozer, MapStruct, and ModelMapper.

The only one work for me in Android gradle build system is ModelMapper. And this is a good example how can we mapping source object to target object by using ModelMapper.

Finally, it’s really easy to use if both source and target object when them are quite the same properties.

If the source target has both matching property name seen like same, like getId(), getMemberId(), getProperId(). ModelMapper mapping strategy has three type:

  1. LOOSE: Allows for source properties to be loosely matched to destination properties by requiring that only the last destination property in a hierarchy be matched.
  2. STANDARD: intelligently matched to destination properties, requiring that all destination properties be matched and all source property names have at least one token matched.
  3. STRICT: For source properties to be strictly matched to destination properties. This strategy allows for complete matching accuracy, ensuring that no mismatches or ambiguity occurs. But it requires that property name tokens on the source and destination side match each other precisely.

I choose STRICT, just want copy the exactly same name.

Written by

Focus in cloud developing and operating with microservice. Bring client business process automation. Every data connect has its worth.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store