Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Seeking info on JAXB and custom annotations

Reply
Thread Tools

Seeking info on JAXB and custom annotations

 
 
Sebastian
Guest
Posts: n/a
 
      12-18-2012
Does anyone know if (and how) it is possible to

a) generate Java classes with custom annotations from xsd schema, using
xjc? (The annotations would be on fields, but placing them on the
corresponding getters would be acceptable.) I have googled a bit, and
one possibiliy appears to be the annox plugin.

b) marshall/unmarshall these classes to XML and back with JAXB,
preserving the custom annotations? I have found no helpful information
on this part of the problem.

By "custom annotations" I mean non-JAXB annotations that would be
written by me.

-- Sebastian
 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      12-19-2012
On 12/18/2012 6:06 PM, Sebastian wrote:
> Does anyone know if (and how) it is possible to
>
> a) generate Java classes with custom annotations from xsd schema, using
> xjc? (The annotations would be on fields, but placing them on the
> corresponding getters would be acceptable.) I have googled a bit, and
> one possibiliy appears to be the annox plugin.


What form would the annotations have in the schema?

XML schema annotations does not seem to be a good match for
Java annotations.

> b) marshall/unmarshall these classes to XML and back with JAXB,
> preserving the custom annotations? I have found no helpful information
> on this part of the problem.


You do not marshall/unmarshall classes. You marshall/unmarshall
objects. But annotations are per class not per object.

I think clarification is needed.

Arne


 
Reply With Quote
 
 
 
 
Sebastian
Guest
Posts: n/a
 
      12-19-2012
Am 19.12.2012 02:17, schrieb Arne Vajh°j:
> On 12/18/2012 6:06 PM, Sebastian wrote:
>> Does anyone know if (and how) it is possible to
>>
>> a) generate Java classes with custom annotations from xsd schema, using
>> xjc? (The annotations would be on fields, but placing them on the
>> corresponding getters would be acceptable.) I have googled a bit, and
>> one possibiliy appears to be the annox plugin.

>
> What form would the annotations have in the schema?
>
> XML schema annotations does not seem to be a good match for
> Java annotations.


The Annotate Plugin page has a good explanation:
http://confluence.highsource.org/dis...nnotate+Plugin

See also the Annox user guide for the view that
in fact Java annotations can be elegantly expressed as XML elements.
http://confluence.highsource.org/display/ANX/User+guide

Unfortunately, I have not been able to get the plugin to work so far,
and am looking for alternative recommendations.

>> b) marshall/unmarshall these classes to XML and back with JAXB,
>> preserving the custom annotations? I have found no helpful information
>> on this part of the problem.

>
> You do not marshall/unmarshall classes. You marshall/unmarshall
> objects. But annotations are per class not per object.
>
> I think clarification is needed.
>
> Arne


I guess I was confused here by the fact that the XML representation of
an object generated by JAXB will not contain annotation elements, but of
course the annotation is part of the Java class that will be
instantiated when unmarshalling.

(I am talking of custom annotation available at runtime via reflection,
i. e. defined in the annotation class with
@Retention(RetentionPolicy.RUNTIME). I want to be able to inspect the
annotation on an object after it has been unmarshalled.)

-- Sebastian




 
Reply With Quote
 
Sebastian
Guest
Posts: n/a
 
      12-19-2012
Am 19.12.2012 12:49, schrieb Sebastian:
> Am 19.12.2012 02:17, schrieb Arne Vajh°j:
>> On 12/18/2012 6:06 PM, Sebastian wrote:
>>> Does anyone know if (and how) it is possible to
>>>
>>> a) generate Java classes with custom annotations from xsd schema, using
>>> xjc? (The annotations would be on fields, but placing them on the
>>> corresponding getters would be acceptable.) I have googled a bit, and
>>> one possibiliy appears to be the annox plugin.

>[snip]


Please don't bother, I retract the question. Meanwhile, I've been able
to integrate the Annotate Plugin for xjc into my maven build, and
generating the annotations works just fine.

-- Sebastian
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
custom annotations in eclipse are not working Franz Java 0 01-14-2008 04:03 PM
jaxb and annotations - is it possible? Wojtas Java 3 09-18-2007 07:23 PM
Java annotations and XML files G. Java 3 02-13-2007 07:38 PM
Partial Bookmarks and Annotations in Mozilla? mtodorov_69@yahoo.com Firefox 4 10-06-2005 02:27 PM
Annotations and Retention Vidar S. Ramdal Java 2 08-19-2005 07:27 AM



Advertisments