Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't see that problem at all. For me <code>xjc</code> generates a <code>Person</code> class with the properties <code>lat</code> and <code>lon</code> with type <code>Double</code>.</p> <p>If I unmarshall an XML file with no <code>&lt;lat&gt;</code> or <code>&lt;lon&gt;</code> elements, then the resulting <code>Person</code> objects has <code>null</code> values for those properties, as I'd expect.</p> <p>I don't know how you get <code>0.0</code> anywhere.</p> <p>My XML Schema:</p> <pre><code>&lt;xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com/person"&gt; &lt;xsd:element name="Person"&gt; &lt;xsd:complexType&gt; &lt;xsd:sequence&gt; &lt;xsd:element name="name" type="xsd:string" /&gt; &lt;xsd:element name="lat" type="xsd:double" minOccurs="0"/&gt; &lt;xsd:element name="lon" type="xsd:double" minOccurs="0"/&gt; &lt;/xsd:sequence&gt; &lt;/xsd:complexType&gt; &lt;/xsd:element&gt; &lt;/xsd:schema&gt; </code></pre> <p>My <code>Test.java</code>:</p> <pre><code>import com.example.person.Person; import javax.xml.bind.JAXB; import java.io.File; public class Test { public static void main(String[] args) { Person p = JAXB.unmarshal(new File("foo.xml"), Person.class); System.out.println(p.getName()); System.out.println(p.getLat()); System.out.println(p.getLon()); } } </code></pre> <p>My <code>foo.xml</code>:</p> <pre><code>&lt;Person&gt; &lt;name&gt;Fred&lt;/name&gt; &lt;lat&gt;1.0&lt;/lat&gt; &lt;/Person&gt; </code></pre> <p>Output:</p> <pre>Fred 1.0 null </pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload