custom wrapper object jaxb

what is custom wrapper object? which scenario we have to use? is it is similar to XSD?

Please advise
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

XSD and wrappers are not related.

They're simply used for collections when using jaxb to marshall. Since collection classes are not known to the jaxb context, you create a wrapper object that is annotated with jaxb and let it wrap the underlying collection.
gudii9Author Commented:
are they used for unmarshalling also?

please advise.

where xjc coming into picture in this?
are they used for unmarshalling also?

where xjc coming into picture in this?

Xjc is simply the binding compiler. Which can compile an xsd into java classes with JAXB.

If your XSD contains a wrapper then the generated java class with also have the wrapper.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gudii9Author Commented:
Xjc is simply the binding compiler. Which can compile an xsd into java classes with JAXB.

is it alternate way of doing unmarshalling directly without writing the code like below


import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;


public class UnmarshallingDemo {

    public static void main (String [] args) {
        try {
            JAXBContext jc = JAXBContext.newInstance ("");

            Unmarshaller u = jc.createUnmarshaller ();

           File f = new File ("item.xml");
           JAXBElement element = (JAXBElement) u.unmarshal (f);

           Item item = (Item) element.getValue ();
           System.out.println (item.getCode ());
           System.out.println (item.getName ());
           System.out.println (item.getPrice ());
       } catch (JAXBException e) {
           e.printStackTrace ();

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.