title: Jaxb API Listener
body: <p>I have created Jaxb Class that contains following listener method but only unmarshall method is working :</p>
  
  <pre><code>void afterUnmarshal(Unmarshaller unmarshaller, Object parent) {
          System.out.println("afterUnmarshal  1");
      }
  
      void beforeMarshal(Marshaller marshaller, Object parent) {
          System.out.println("beforeMarshal  2");
      }
  
      void beforeUnmarshal(Unmarshaller unmarshaller, Object parent) {
          System.out.println("beforeUnmarshal  3");
      }
  
      void afterMarshal(Marshaller marshaller, Object parent) {
          System.out.println("afterMarshal  4");
      }
  </code></pre>
  
  <p><strong>OutPut :</strong></p>
  
  <pre><code>beforeUnmarshal  3
  afterUnmarshal  1
  </code></pre>
  
  <p>No marshall method is called on execution of marshalling code .</p>
  
  <hr>
  
  <p><strong>Updated Question : 
  Problem :</strong> beforeMarshal  Customer called two times .
  <strong>OutPut :</strong> </p>
  
  <pre><code>afterUnmarshal  Address
  afterUnmarshal  Customer
  beforeMarshal  Customer
  beforeMarshal  Customer
  beforeMarshal  Address
  </code></pre>
  
  <p><strong>Program :</strong></p>
  
  <pre><code> public class Demo {
  
          public static void main(String[] args) throws Exception {
              JAXBContext jc = JAXBContext.newInstance(Customer.class,ObjectFactory.class);
  
              Unmarshaller u = jc.createUnmarshaller();
              File xml = new File("src/testRJE/input.xml");
              Customer customer = (Customer) u.unmarshal(xml);
  
              Marshaller m = jc.createMarshaller();
              m.marshal(customer, xml);
          }
  
      }
  
  
      @XmlRootElement
      @XmlAccessorType(XmlAccessType.FIELD)
      public class Customer {
  
        @XmlElementRef(name = "billing-address")
        @XmlJavaTypeAdapter(AddressAdapter.class)
        private Address address;
  
          public Address getAddress() {
              return address;
          }
  
  
          void afterUnmarshal(Unmarshaller unmarshaller, Object parent) {//XML to Object
          System.out.println("afterUnmarshal  Customer");
      }
  
      void beforeMarshal(Marshaller marshaller ) {
          System.out.println("beforeMarshal  Customer");
      }
  
      }
  
      @XmlAccessorType(XmlAccessType.FIELD)
      public class Address {
  
          public Address() {
          }
  
  
          private String street;
  
          private String city;
  
        void afterUnmarshal(Unmarshaller unmarshaller, Object parent) {
          System.out.println("afterUnmarshal  Address");
      }
  
      void beforeMarshal(Marshaller marshaller ) {
          System.out.println("beforeMarshal  Address");
      }
  
  
      }
  </code></pre>