I had a hard time formulating this question, which may be why I haven't found a solution I'm happy with yet.
Further explanation: I have a scheme which I run through with jaxws in 2 different occations but the same version of the library. One is input to my service and the other is the output (yes, the same for now)
I get the same structure, let's say this is what I get:
//1st generation
package package1;
public class Object1{
int number;
//getters and setters
}
//2nd generation
package package2;
public class Object2{
int number;
//getters and setters
}
How would I go about to set objects from the 2 classes to eachother? (Object1 = Object2)
In my case, the classes are the same name. I haven't used reflection before, and from what I've read it would be a mistake to use it in this particular service due to performance requirements. If there is some way to modify the classes to implement a common interface, it would probably work.
Perhaps a mapping framework is what you are looking for?
There is one here (that claims to be fast) --> https://code.google.com/p/orika/
The easiest way is using BeanUtils which uses reflection:
http://commons.apache.org/proper/commons-beanutils/apidocs/org/apache/commons/beanutils/BeanUtils.html (Look for the copyProperties method)
It can be done like this:
BeanUtils.copyProperties(dest, source);
Since performance is an issue, I would go for the BeanUtils version first and try to measure how fast it is. It might be fast enough since this is in memory operations. But if you have a large object graph with many nested levels, it might not work because all the dependants are located in a different package and thus are different types..
If, however, you are in control of the XML schemas, you can define a common namespace for the types you are using and thus only one version of these classes will be created (they will share the same package).
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments