title: Java Builder Pattern - deep object copy
body: <p>I have a Jaxb object that has an object tree 3 deep. I have created a seperate object that mirrors this Jaxb object. I am using the builder pattern to copy values from Jaxb to the bean. The issue is, when building A, I require an instance of B. But, the verion of B that the builder requires is different from the Jaxb version of B -the 'source'.</p>
  
  <p>How do I build A?</p>
  
  <pre><code>public class A {
      private B b;
  
      public void setB(B b) {
          this.b = b;
      }
  
      public static class ABuilder {
          private B b;
  
          public ABuilder withB(B b) {
              this.b = b;
              return this;
          }
  
          A build() {
              A a = new A();
              a.setB(b);
  
              return a;
          }
      }
  }
  
  class B {
      private C c;
      private String name;
  }
  
  class C {
      private int count;
  }
  
  
  class myMain {
      com.myJaxb.B jaxbB; 
      A myA = new A.ABuilder().withB(jaxbB).build();  //error - withB doesnt take jaxb B
  }
  </code></pre>