Wednesday Apr 25, 2007

JAXB Tip

If you are using JAXB for XML to Java binding and geting javax.xml.bind.UnmarshalException: Unexpected element blah blah blah... the first thing you can do is to call setValidating(true) on Unmarshaller object. i.e.

   JAXBContext jc = JAXBContext.newInstance("com.sun.java.xml.ns.portlet.portlet_app_2_0");
   // create an Unmarshaller
   Unmarshaller u = jc.createUnmarshaller();
    u.setValidating(true); 

This will help in getting little more details about the problem. For example, if your schema has declared <sequence> constraints on certain elements and your XML is not following it, the validation handler will report that certain tag name (element) is NOT allowed at this place and what all possible elements can appear after certain element.

One caveat here - setValidating() is a deprecated method and should be used only for debugging purpose. 

About

manishkg

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today