title: Jaxb:global binding Double Type Conversion Using XMLAdapter
body: <p>I have an element defined as an xsd:double. If I try and place a value say 285 into the element and then I marshal it I get an output of 285.0... That is fine .However, if I put a value in of say  285292746, I get an output of  2.85292746E8 when I marshal.
  I like something so that double output does not get converted into scientific notation with decimal? Basically I want 285292746 or 2852292746.0000000</p>
  
  <p>java.lang.Double.toString() uses "computerized scientific notation" for certain values which produce isues for xml. </p>
  
  <p>I  know double representation of given value is fine. But  the fact the value was in exponential format,  The system that I am working on is accept my XML but does not know what to do with the exponential value and that causes my program not to work correctly.  Changing xsd:double type in WSDL or server is not feasible for me. I am working on client side. </p>
  
  <p>I came across Jaxb:binding for xsd:double type. I am still having hard time to fix the issue to send values double value in non –exponents format.</p>
  
  <pre><code>package com.logger.client 
  import javax.xml.bind.annotation.adapters.XmlAdapter;
  import javax.xml.bind.DatatypeConverter;
  
  public class JaxbDoubleSerializer  extends XmlAdapter&lt;String, Double&gt;
  {
  
  
      public Double unmarshal(String value) {
          return ((double)javax.xml.bind.DatatypeConverter.parseDouble(value));
      }
  
      public String marshal(Double value) {
          if (value == null) {
              return null;
          }
          return (javax.xml.bind.DatatypeConverter.printDouble((double)(double)value));
      }
  
  }
  </code></pre>
  
  <p>I need help how to use DoubleSerializer so that I can pass values without exponents. I tried using xmlAdapter Annotation in my class MyLogClient.java. I need to know how I can solve this situation.</p>
  
  <pre><code>package com.logger.client 
  import javax.xml.ws.BindingProvider;
  import javax.xml.bind.JAXBElement;import javax.xml.bind.JAXBContext;
  import javax.xml.bind.JAXBException;
  import javax.xml.bind.annotation.XmlAccessType;
  import javax.xml.bind.annotation.XmlAccessorType;
  import javax.xml.bind.annotation.XmlElement;
  import javax.xml.bind.annotation.XmlRootElement;
  import javax.xml.bind.annotation.XmlType;
  import javax.xml.bind.annotation.XmlValue;
  
  
  public class MyLogClient 
  {
     //Private member fields
  
    /** Object factory used to create user-and-role specific objects. */
      private static final ObjectFactory _of = new ObjectFactory();
  
       @XmlJavaTypeAdapter(JaxbDoubleSerializer.class)
     public JAXBElement&lt;Double&gt; msgFileId;
  
         @XmlJavaTypeAdapter(JaxbDoubleSerializer.class)
     public Double dNumber;
  
  
  public final void createEntry;
      (
          final String userName,
          final String time,
          final String logMsgStringId,
          final Params logMsgParamsVal,
          final Integer logMessageFieldID
      )
  
      throws JAXBException
      {
  
         JAXBElement&lt;String&gt; username = _of.createParamsParam(userName);
        JAXBElement&lt;String&gt; strTime       = _of.createLogRequestTime(time);
  
  
          // Build the LogRequest request.
         final LogRequest _LogRequest = _of.createLogRequest();
         _LogRequest.setUserName(userName);
         _LogRequest.setTime(strTime);
  
          //Following is the main problem
          int nMsgArgs =  285292746;
         dNumber = Double.parseDouble(Integer.toString(nMsgArgs));  
        //After parsing double Value I get dNumber is now  2.85292746E8
  
        //MsgFile Id is of Type JAXBElement&lt;Double&gt;
        //CreateLogMessageIdentifier takes Double param
        //So the main problem is here..the value of double field in soap request 
        //is being sent in exponential format. I need to send as I explained above
        //285292746.
  
         msgFileId   = _of.createLogMessageIdentifier(dNumber); 
  
        JAXBElement&lt;String&gt; strIdVal = _of.createLogMessageFileId(logMsgStringId);
  
        final LogMessage logMessage = _of.createLogMessage();
  
       JAXBElement&lt;Params&gt; _logMsgParams =_of.createLogMessageParams(logMsgParamsVal);
  
       //Following is where I am trying to use marshall for double type.
  
       JAXBContext context = JAXBContext.newInstance("package com.logger.client ");
       context.createMarshaller().marshal(msgFileId, System.out);
  
        logMessage.setIdentifier(msgFileId);  //Method takes JAXBElement&lt;Double&gt;
  
        logMessage.setFileId(strIdVal );
        logMessage.setParams(_logMsgParams);
  
        JAXBElement&lt;LogMessage&gt; logMsgValue = _of.createLogRequestLogMessage(logMessage);
  
  
          _LogRequest.setLogMessage(logMsgValue);
  
          // Set the log entry
          port.log(_LogRequest); //Request is sent to server.
  </code></pre>
  
  <p>}</p>
  
  <p>WSDL xsd:type declaration is below:-</p>
  
  <pre><code>  &lt;xsd:complexType name="LogMessage"&gt;
           &lt;xsd:sequence&gt;
          &lt;xsd:element name="fileId" type="xsd:string" minOccurs="0" nillable="true" /&gt;
          &lt;xsd:element name="identifier" type="xsd:double" minOccurs="0" nillable="true" /&gt;
          &lt;xsd:element name="params" type="tns:Params" minOccurs="0" nillable="true" /&gt;
           &lt;/xsd:sequence&gt;
             &lt;/xsd:complexType&gt;
  </code></pre>
  
  <p>Output for identifier field is:-</p>
  
  <pre><code>     &lt;identifier&gt; 2.85292746E8&lt;/indentifier&gt; 
  
  Whereas I want to send as. Because system does accept/recognize following types.
  
  &lt;identifier&gt; 285292746&lt;/indentifier&gt; 
  or 
  &lt;identifier&gt; 285292746.00000000&lt;/indentifier&gt; 
  </code></pre>