File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes JAXB does not generate @XmlRootElement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "JAXB does not generate @XmlRootElement" Watch "JAXB does not generate @XmlRootElement" New topic
Author

JAXB does not generate @XmlRootElement

Anish Shah
Greenhorn

Joined: Sep 24, 2008
Posts: 20
Why does JAXB put @XmlRootElement sometimes but not always?

The above link is preety much where i am stuck.. It does not generate @XmlRootElement.. I also tried using their solution of :

jaxb-xjc version : jaxb-xjc-2.1.10.jar.. so i have changed my jaxb:version to 2.1 from 1.0 above...

Generated Code from above XSD



I just can't get it to generate @XmlRootElement over my class...something like below


(P.S.) I need it for my web services implementation...

Thanks you very much...
Kris Schneider
Ranch Hand

Joined: Feb 14, 2001
Posts: 71
This probably belongs in the "Web Services" forum...

You haven't actually defined any elements in your schema, just a type. Obviously, you have to decide what makes the most sense in terms of your schema design, but what if you change it to something like:



Read the java.net blog entry a bit more carefully and you'll see that it's really addressing elements and not types...which makes sense given the name of the annotation: XmlRootElement
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

Kris Schneider wrote:This probably belongs in the "Web Services" forum...

So that's where this thread is going.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Take a look at this web page: http://weblogs.java.net/blog/2006/03/03/why-does-jaxb-put-xmlrootelement-sometimes-not-always
It should answer your question.
Best wishes!
Kris Schneider
Ranch Hand

Joined: Feb 14, 2001
Posts: 71
Ivan Krizsan wrote:Take a look at this web page...


Which is the exact same page referenced in the original post...on the first line.

Ivan Krizsan wrote:It should answer your question.


If hindsight is any guide, I'm guessing not.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Kris Schneider wrote:
Which is the exact same page referenced in the original post...on the first line.

Sorry, I did not see the link, my fault.
Anish Shah
Greenhorn

Joined: Sep 24, 2008
Posts: 20
Kris.. you were so right.. its about the Element as you said.. I had to change my design around but it worked.. Thank you very much for your advice..
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JAXB does not generate @XmlRootElement
 
Similar Threads
InvalidMappingException
problem to unmarshal xml file who have element with prefix
variations in generated classes
Doubt on the JAXB: XML Schema to Java mapping for anonymous complex type.
Clarification Requested - XML recordset & JAXB classes