title: how to set default value for element if that element is absent in xml file through jaxb unmarshalling in java
body: <p>The issue is I want to set a default value for "name" element which is absent in input.xml file.How can I achieve this through jaxb?, I dont want to do it through java model. Is there a way to get it through shema or through jaxb.
  Below is the code:</p>
  
  <p><strong>1. customer.xsd</strong> </p>
  
  <pre><code>&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  
      &lt;xs:element name="customer"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element name="name" type="stringMaxSize5" minOccurs="0" default="ss"/&gt;
                  &lt;xs:element name="phone-number" type="xs:integer" minOccurs="0" default="200" /&gt;
               &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
      &lt;xs:simpleType name="stringMaxSize5"&gt;
          &lt;xs:restriction base="xs:string"&gt;
              &lt;xs:maxLength value="5"/&gt;
          &lt;/xs:restriction&gt;
      &lt;/xs:simpleType&gt;
  
  &lt;/xs:schema&gt; 
  </code></pre>
  
  <p><strong>2. Customer.model</strong></p>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  @XmlType(name = "", propOrder = {
      "name",
      "phoneNumber"
  })
  @XmlRootElement(name = "customer")
  public class Customer {
  
      @XmlElement(defaultValue = "ss")
      protected String name;
      @XmlElement(name = "phone-number", defaultValue = "200")
      protected BigInteger phoneNumber;
      public String getName() {
          return name;
      }
      public void setName(String value) {
          this.name = value;
      }
      public BigInteger getPhoneNumber() {
          return phoneNumber;
      }
      public void setPhoneNumber(BigInteger value) {
          this.phoneNumber = value;
      }
  }
  </code></pre>
  
  <p><strong>3. input.xml</strong></p>
  
  <pre><code>&lt;customer&gt;
  
  &lt;/customer&gt;
  </code></pre>
  
  <p>For unmarshalling using the below code:</p>
  
  <pre><code>SchemaFactory sf =SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
  Schema schema = sf.newSchema(new File("customer.xsd"));
  
  JAXBContext jc = JAXBContext.newInstance(Customer.class);
  Unmarshaller unmarshaller = jc.createUnmarshaller();
  unmarshaller.setSchema(schema);
  Customer customer = (Customer) unmarshaller.unmarshal(new File("input.xml"));
  System.out.println(customer.getName() + "   " + customer.getPhoneNumber());
  </code></pre>
  
  <p>By running this I am getting null value for the name and If I use the below input.xml file with "name" element  then I am getting default value for name field.</p>
  
  <pre><code>input.xml file:
  &lt;customer&gt;&lt;name/&gt;&lt;/customer&gt;
  </code></pre>
  
  <p>So,how to set default value for missing element through jaxb?</p>