Posts

Showing posts with the label XML

JAXB - II (jaxb.index file and ObjectFactory)

I was getting a Exception like, javax.xml.bind.JAXBException: "doesnt contain ObjectFactory.class or jaxb.index" while trying to create a JAXBContext using JAXBContext.newInstance(String contextPath). It took me a while to figure out what went wrong. So now that I've got things working correctly, I thought I'd post this example and solution to hopefully save you some time. When we create a marshaller, we first need to create a JAXBContext via its newInstance() factory method. You can create a context for a specific JAXB class  or you can create a context for a list of packages. There are two ways to resolve this issue :    - By creating ObjectFactory   - By adding jaxb.index file jaxb.index : The jaxb.index file is a text file contains a listing of the classes on the containing package that have JAXB annotations. Note : The name of the clases is their simple name not their classified name.   Rather than creating a ObjectFactory, I guess adding ...

Java Architecture for XML Binding (JAXB)

Overview:  - Java Architecture for XML Binding (JAXB) is a Java standard that defines how Java objects are converted to/from XML (specified using a standard set of mappings).  - It defines a programmer API for reading and writing Java objects to / from XML documents and a service provider which / from from XML documents allows the selection of the JAXB implementation  - It makes reading  and writing of XML via Java very easy.  - It allows Java developers to access and process XML data without having to know XML or XML processing  - It is used heavily by JAX-WS    - It provides ways to generate XML content from a Java representation , to generate a Java representation from XML file , to generate XML schema from Java Objects  - The JAXBContext class provides the client's entry point to the JAXB API. It provides an abstraction for managing the XML/Java binding information necessary to implement the JAXB binding framework operati...