background image

Unmarshal Validate Example

<< JAXB Examples Output | The default JAXB Unmarshaller >>
<< JAXB Examples Output | The default JAXB Unmarshaller >>
U
NMARSHAL
V
ALIDATE
E
XAMPLE
33
<city>Cambridge</city>
<state>MA</state>
<zip>12345</zip>
</shipTo>
<billTo country="US">
<name>John Bob</name>
<street>242 Main Street</street>
<city>Beverly Hills</city>
<state>CA</state>
<zip>90210</zip>
</billTo>
<items>
<item partNum="242-NO">
<productName>Nosferatu - Special Edition (1929)</productName>
<quantity>5</quantity>
<USPrice>19.99</USPrice>
</item>
<item partNum="242-MU">
<productName>The Mummy (1959)</productName>
<quantity>3</quantity>
<USPrice>19.98</USPrice>
</item>
<item partNum="242-GZ">
<productName>
Godzilla and Mothra: Battle for Earth/Godzilla vs. King Ghidora
</productName>
<quantity>3</quantity>
<USPrice>27.95</USPrice>
</item>
</items>
</purchaseOrder>
Unmarshal Validate Example
The Unmarshal Validate example demonstrates how to enable validation during
unmarshalling (Unmarshal-Time Validation). Note that JAXB provides functions
for validation during unmarshalling but not during marshalling. Validation is
explained in more detail in More About Validation (page 4).
1. The
<INSTALL>/examples/jaxb/unmarshal-validate/Main.java
class declares imports for three standard Java classes plus seven JAXB
binding framework classes and the
primer.po
package:
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigDecimal;
import javax.xml.bind.JAXBContext;