I have created Jaxb DTOs using Maven profile. Something like this:
class Parent { ChildOne one; }
class ChildOne { ChildTwo two; }
class ChildTwo { ChildThree three; }
class ChildThree { ChildFour four; }
The hierarchy roughly goes on till ChildEight.
class ChildEight { String valueToBeStored; }
I have to set the value of the string of the last ChildEight. The way it is currently being done is by creating each ChildObject instance and setting it to the parent reference.
Parent parent = new Parent();
ChildOne one = new ChildOne();
ChildTwo two = new ChildTwo();
ChildThree three = new ChildThree();
...
ChildEight eight = new ChildEight();
eight.setValueToBeStored("Hurray");
seven.setEight(eight);
...
one.setChildTwo(two);
parent.setChildOne(one);
My question is, instead of creating all the dependent objects (which are not going to be used again), is there a better or more efficient way to achieve the same result?
Notes:
- The instances are not created so I cannot use
BeanUtils
orPropertyUtils
to copy objects, but I am expecting to find a similar way to make my life easier. - There are no constructors with arguments.
- Child Five contains a List of ChildSix Objects and has a getter which returns the reference to a live list. So we can use getChildSixList().add() instead of using a setter.