Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Copy value from attribute a1 in class A.java to attribute b1 in class B.java using 0bject mapping

 
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone suggest a pragmatic way (e.g. use of object mappint e.g. Dozer, Smooky etc.) without writing code to copy properties from one object to another when the name of the properties may not match. If names of the properties did match in two objects (A.java and B.java), I could have used copyProperties. I also do not want to write tedious code to copy value of attribute a1 from A.java to value b1 in B.java.

Can you suggest of easy way of doing it using object mapping API of Dozer, Smooky etc.?

This is the problem:

Value of attribute a1 (which has public getter and setter) in class A.java has to to be copied to the value of attribute b1 (which has public getter and setter) of class B.java. As the name of the attributes are different (a1 in A.java and b1 in B.java), I cannot use copyProperties. I also do not want to write tedious Java code to pass the value of a1 of A.java to b1 of B.java.

Is it possible to set up Dozer, Smooky etc. that will copy value of a1 attribute of A.java into b1 attribute of B.java?

If I can do that, I can only write configuration code to do so.

Any advice will be appreciated.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic