Loading
Marshall and UnMarshall with JAXB

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  Marshall and UnMarshall with JAXB ?


Ans)

Jaxb Marshalling :
This converts your Java Object to XML and write that to "StringWriter()".
                //Result messageString = null;
                JAXBContext jc;
                StringWriter sw = null;
                try {
                        jc = JAXBContext.newInstance( "com.test.generated" );
                        Marshaller marshaller = jc.createMarshaller();  
                        sw = new StringWriter();
                        marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );  
                        marshaller.marshal( yourObject, sw );
   
             } catch (JAXBException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }  
Jaxb UnMarshalling :
This converts the "message" string to YourJavaObject.
                       StringReader reader = new StringReader(message);
                        jc = JAXBContext.newInstance("com.test.generated");
                        Marshaller marshaller = jc.createMarshaller();
                        javax.xml.bind.Unmarshaller unmarshaller = jc.createUnmarshaller();
                        InputStream is = new ByteArrayInputStream(message.getBytes());
                        jAXBElement = (YourJavaObject) unmarshaller.unmarshal(reader);



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

Marshall and UnMarshall with JAXB


Marshall and UnMarshall with JAXB

-------------------------------------------------------------------------------------------------------



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free