Seeking info on JAXB and custom annotations

Discussion in 'Java' started by Sebastian, Dec 18, 2012.

  1. Sebastian

    Sebastian Guest

    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
    Sebastian, Dec 18, 2012
    #1
    1. Advertising

  2. Sebastian

    Arne Vajhøj Guest

    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
    Arne Vajhøj, Dec 19, 2012
    #2
    1. Advertising

  3. Sebastian

    Sebastian Guest

    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/display/J2B/Annotate 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, Dec 19, 2012
    #3
  4. Sebastian

    Sebastian Guest

    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
    Sebastian, Dec 19, 2012
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vidar S. Ramdal

    Annotations and Retention

    Vidar S. Ramdal, Aug 18, 2005, in forum: Java
    Replies:
    2
    Views:
    650
    Vidar S. Ramdal
    Aug 19, 2005
  2. Wojtas
    Replies:
    3
    Views:
    315
    Tim Hallwyl
    Sep 18, 2007
  3. Franz
    Replies:
    0
    Views:
    1,010
    Franz
    Jan 14, 2008
  4. Brett Ritter
    Replies:
    4
    Views:
    379
    Bruno Desthuilliers
    Jul 24, 2008
  5. 7rans
    Replies:
    3
    Views:
    108
    Matt Todd
    Aug 4, 2006
Loading...

Share This Page