jaxb
  1. jaxb
  2. JAXB-983

JAXB does not support meta class annotations

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.2.7
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      JAXB reads annotations directly from scanned classes by calling directly java.lang.Class.getAnnotation(Class<A>) This means that Java classes must be annotated directly by e.g. @XmlRootElement, @XmlType etc.

      JAXB should read also meta annotations of scanned class annotations i.e. let's take the following example:

      Bean.java
      @XmlRootElement
      @XmlType
      // ... other annotations
      @Retention(RUNTIME)
      @Target(TYPE)
      public @interface Bean {
      }
      

      and then a Java bean:

      Input.java
      @Bean
      public class Input {
      
        BigInteger amount;
        Account account;
        // remainder omitted
      }
      

      In such case if you execute this:

      Main.java
      Input input = new Input();
      input.setAmount(new BigInteger(1000));
      // remainder omitted
      JAXBContext.newInstance(Input.class).createMarshaller().marshal(input, System.out);
      

      you will get an error:

      Exception in thread "main" javax.xml.bind.MarshalException
       - with linked exception:
      [com.sun.istack.SAXException2: unable to marshal type "Input" as an element 
      because it is missing an @XmlRootElement annotation]
      

      IMHO it's a bug. JAXB should support annotations annotated with javax.xml.bind annotations. I will send you a patch for class annotations but it should be also the case for fields and methods, I think.

        Activity

        Hide
        Przemyslaw Bielicki added a comment -

        patch sent to dev@jaxb.java.net

        Show
        Przemyslaw Bielicki added a comment - patch sent to dev@jaxb.java.net
        Show
        Przemyslaw Bielicki added a comment - patch available on github: https://github.com/pbielicki/jaxb/commit/4bafc09fc6a2be203329e3e2423bf9143698828b

          People

          • Assignee:
            Iaroslav Savytskyi
            Reporter:
            Przemyslaw Bielicki
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: