eclipse-ee4j / jaxb-ri

Jaxb RI
https://eclipse-ee4j.github.io/jaxb-ri/
BSD 3-Clause "New" or "Revised" License
202 stars 110 forks source link

JAXB does not support meta class annotations #983

Open Tomas-Kraus opened 10 years ago

Tomas-Kraus commented 10 years ago

JAXB reads annotations directly from scanned classes by calling directly java.lang.Class.getAnnotation(Class) 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:

<font color="red">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]</font>

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.

Affected Versions

[2.2.7]

Tomas-Kraus commented 6 years ago
Tomas-Kraus commented 10 years ago

@glassfishrobot Commented Reported by pbielicki

Tomas-Kraus commented 10 years ago

@glassfishrobot Commented pbielicki said: patch sent to dev@jaxb.java.net

Tomas-Kraus commented 10 years ago

@glassfishrobot Commented pbielicki said: patch available on github: https://github.com/pbielicki/jaxb/commit/4bafc09fc6a2be203329e3e2423bf9143698828b

Tomas-Kraus commented 10 years ago

@glassfishrobot Commented Was assigned to yaroska

Tomas-Kraus commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA JAXB-983