Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Seeking info on JAXB and custom annotations (http://www.velocityreviews.com/forums/t955634-seeking-info-on-jaxb-and-custom-annotations.html)

Sebastian 12-18-2012 11:06 PM

Seeking info on JAXB and custom annotations
 
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

Arne Vajhøj 12-19-2012 01:17 AM

Re: Seeking info on JAXB and custom annotations
 
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



Sebastian 12-19-2012 11:49 AM

Re: Seeking info on JAXB and custom annotations
 
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





Sebastian 12-19-2012 06:23 PM

Re: Seeking info on JAXB and custom annotations
 
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


All times are GMT. The time now is 05:49 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57