How do you set generated classes from the same schema but in different generations to eachothers request/response objects without traversing them?

Henrik Lindgren

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.

Lars Juel Jensen

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Creating two objects of the same classes from different imports made them look as different classes

From Dev

How do you access variables from different classes in Java?

From Dev

mips extract certain bits from register and set them to a different register in the same place without changing the rest

From Dev

Classes and Sub-classes - how do you track them?

From Dev

How to ignore classes from imported schemas in the generated jar for a particular schema

From Dev

How do you grep and save 2 different results into one file without them overwriting each other?

From Dev

ReactJS - How do you set the state of a component from a different component?

From Dev

How do you control callbacks and stop them from returning without using async?

From Dev

How do I prevent two of the same random numbers being generated from two different variables in Python?

From Dev

How to set relation between two objects without fetch them

From Dev

How do you keep track of multiple properties of a string without traversing it multiple times?

From Dev

How do I set a different type of property in mongoose schema from the defined type?

From Dev

InternalsVisibleTo - How do you prevent someone from creating an assembly with same name and get access to internal classes or methods?

From Dev

How to define classes using 2 different objects calling the same methods

From Dev

How do you fill an array with objects from a different class? deteils below

From Dev

MySQL considers 'е' and 'ё' equal, how do I set it to consider them different?

From Dev

How to get different outputs from the same Keras layer and then combine them?

From Dev

How do you count the first column generated from uniq -c

From Dev

Create an array of classes and then instantiate objects from them

From Dev

How do you Marshal multiple sets of objects with different values in JAXB?

From Dev

How do you set a value from a getter?

From Dev

How do you render views in an each loop without container objects?

From Dev

Why do my objects have different heights even when I gave them the same?

From Dev

Declaring multiple objects of different classes with the same name

From Dev

How do you send messages between different users of the same app?

From Dev

How do you have the same IBOutlet on two different ViewControllers if possible?

From Dev

How do you change multiple CSS as the same time with different clicks?

From Dev

Generation of XSD restrictions in a schema generated from Java JAXB annotated classes

From Dev

How do you apply a predicate while traversing through a fulfilled NSManagedObject?

Related Related

  1. 1

    Creating two objects of the same classes from different imports made them look as different classes

  2. 2

    How do you access variables from different classes in Java?

  3. 3

    mips extract certain bits from register and set them to a different register in the same place without changing the rest

  4. 4

    Classes and Sub-classes - how do you track them?

  5. 5

    How to ignore classes from imported schemas in the generated jar for a particular schema

  6. 6

    How do you grep and save 2 different results into one file without them overwriting each other?

  7. 7

    ReactJS - How do you set the state of a component from a different component?

  8. 8

    How do you control callbacks and stop them from returning without using async?

  9. 9

    How do I prevent two of the same random numbers being generated from two different variables in Python?

  10. 10

    How to set relation between two objects without fetch them

  11. 11

    How do you keep track of multiple properties of a string without traversing it multiple times?

  12. 12

    How do I set a different type of property in mongoose schema from the defined type?

  13. 13

    InternalsVisibleTo - How do you prevent someone from creating an assembly with same name and get access to internal classes or methods?

  14. 14

    How to define classes using 2 different objects calling the same methods

  15. 15

    How do you fill an array with objects from a different class? deteils below

  16. 16

    MySQL considers 'е' and 'ё' equal, how do I set it to consider them different?

  17. 17

    How to get different outputs from the same Keras layer and then combine them?

  18. 18

    How do you count the first column generated from uniq -c

  19. 19

    Create an array of classes and then instantiate objects from them

  20. 20

    How do you Marshal multiple sets of objects with different values in JAXB?

  21. 21

    How do you set a value from a getter?

  22. 22

    How do you render views in an each loop without container objects?

  23. 23

    Why do my objects have different heights even when I gave them the same?

  24. 24

    Declaring multiple objects of different classes with the same name

  25. 25

    How do you send messages between different users of the same app?

  26. 26

    How do you have the same IBOutlet on two different ViewControllers if possible?

  27. 27

    How do you change multiple CSS as the same time with different clicks?

  28. 28

    Generation of XSD restrictions in a schema generated from Java JAXB annotated classes

  29. 29

    How do you apply a predicate while traversing through a fulfilled NSManagedObject?

HotTag

Archive