• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

General question on JAXB annotations generated when using xjc

 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

There are a lot of JAXB annotations like XmlAccessorType, XMLAttribute, etc. When I take any sample XML schema file, and run xjc, it generates Java class representations of the types and elements in the schema. I also see that it generates very minimal JAXB-specific annotations, e.g. @XmlAccessorType(XmlAccessType.FIELD) at the class level. However, XmlAccessType can also have other values like NONE, PROPERTY and PUBLIC_MEMBER, and can also be specified at the field level.

Question: Is there a way to create the xsd schema or specify xjc options to make it generate the specific class and member level annotations that we need? Or is it standard practice to take the generated files, and then customize them?

Thanks in advance!

Srini
 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
Take a look at this web page: http://java.sun.com/webservices/docs/2.0/tutorial/doc/JAXBUsing4.html
There is a section speaking about the reasons for customizing JAXB bindings.
Note that if you modify annotations in Java classes generated by the XJC schema compiler, then the result may be that the mapping no longer corresponds to the original XML schema. Thus it should be done with care.
Personally, I usually work with the XML schema as the master and generate classes using XJC. If I need to change something, I modify the XML schema and regenerate the classes.
Best wishes!
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While I agree the link provided is an excellent source of info on generating customized JAXB bindings, I don't think it addresses the question posed. Does anyone have a solution to this?
 
R Srini
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. Actually, Ivan did provide an answer to the piece I was looking for, i.e. use the schema as the master and modify the schema as needed instead of customizing the generated files. Please describe exactly are you looking for - maybe give a specific example to help get it started - and I am sure you will get some suggestions from the group in response .
 
Timo Taye
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well this is a little embarrassing. What I want to do is use XJB to generate JAXB annotated classes that needn't be modified by hand at all and are created with the annotations I want. Specifically, I am interested in setting XmlAccessType to NONE rather than FIELD which is the default. I am willing to use bindings customizations or even write a XJC plugin if I must but am having a difficult time finding information. In general, it appears there may be a bit of a gap between the options XJC supports verses those that are available to users hand writing classes. One example of this I am seeing is the inability to specify an adapter class for a complex type (see https://jaxb.dev.java.net/issues/show_bug.cgi?id=209) in my schema.
 
R Srini
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Specifically, I am interested in setting XmlAccessType to NONE rather than FIELD which is the default.


Hi. Were you able to figure this out? If yes, kindly share your solution. Thank you!
 
Timo Taye
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunately I wasn't able to find a solution. As a temporary work around (until I have time to revisit the problem) I have written a script that gets called by ant after XJC has run and performs the desired string replacements.
 
I do some of my very best work in water. Like this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic