• Post Reply Bookmark Topic Watch Topic
  • New Topic

transfer of data between object  RSS feed

 
Vaibhav Deshpande
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I am getting one transfer Object from my backend. I want to copy this trasfer object data into my model beans (POJOs). The problem is that transfer object and my model beans do not have same structrue or mapping. I want a genric way to do this copying of data. otheriwse it will be tedious to write lengthy code.

thanks in advance.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
Herman Schelti
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Vaibhav,

for copying properties of beans, I use copyProperties(...) of class org.apache.commons.beanutils.BeanUtils.

It's not very generic, but it makes your code shorter.

Herman
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A reflection-based method, like the one Herman Scheltinga suggests sounds like a good candidate for your solution. However, you say that the objects you are copying bfrom and to do not have the same structure, so reflection may well not be possible. Can you give us an example of the type of classes your are transfering the values between?
 
Vaibhav Deshpande
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

thanks for your quick replies.

As an example we can say my Transfer object having one variable which is returning a "int" value. But my POJO which need to be set have a class object for this int. It means I need to map this int to a class.

So reflection will be not useful for me.

Main prob is that structure of transfter Onject from backend and POJO wghich will be used to display data are diffrent.

another example is my backend is sending me 2 boolean values true and false and in POJO this is actually class which will showing drop down on screen.

thanks,

Vaibhav
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Main prob is that structure of transfter Onject from backend and POJO wghich will be used to display data are diffrent.

Different how? Can you post some example code?
 
Murad Iqbal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you will have to write lengthy code to do this copying if I understand you correctly. You can change your Transfer class to have a getPOJO() method which creates a POJO object after doing appropriate mapping. Alternatively you may want to subclass the Transfer object if you dont want the original class to be altered and write that method in your subclass. If you do not want to touch your backend classes, you can pass on a Transfer object to your POJO and have a constructor in your POJO which accepts a Transfer object.
 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now if i understand you well enough , You intend to transfer an object's value to another and the objects are not the same, It might be similar to a Project i once did that is Objects needed to be transfered from one system to the other my solution then was XML. I found a way to convert object A to Literal XML , then when the system transmit the XML Data. A Converter at the Other end converts the XML back into Object B. This way all parties remained Happy
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!