custom wrapper object jaxb

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

https://jaxb.java.net/tutorial/section_6_2_7_7-Wrapping-Repeated-Elements-XmlElementWrapper.html

Please advise
LVL 7
gudii9Asked:
Who is Participating?
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.

gurpsbassiCommented:
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.
0
gudii9Author Commented:
are they used for unmarshalling also?

please advise.

where xjc coming into picture in this?
0
gurpsbassiCommented:
are they used for unmarshalling also?
Yes

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.
0

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 java.io.File;

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

import blog.thoughts.on.java.Item;

public class UnmarshallingDemo {

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

            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

0
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
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.