I can't understand why this JAXB IllegalAnnotationException is thrown

后端 未结 12 1715
渐次进展
渐次进展 2020-12-13 02:03

This is my XML file:


    
    
    
                   


        
相关标签:
12条回答
  • 2020-12-13 02:41

    One of the following may cause the exception:

    1. Add an empty public constructor to your Fields class, JAXB uses reflection to load your classes, that's why the exception is thrown.
    2. Add separate getter and setter for your list.
    0 讨论(0)
  • 2020-12-13 02:44

    I can't understand why this JAXB IllegalAnnotationException is thrown

    I also was getting the ### counts of IllegalAnnotationExceptions exception and it seemed to be due to an improper dependency hierarchy in my Spring wiring.

    I figured it out by putting a breakpoint in the JAXB code when it does the throw. For me this was at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(). Then I dumped the list variable which gives something like:

    [org.mortbay.jetty.Handler is an interface, and JAXB can't handle interfaces.
    this problem is related to the following location:
        at org.mortbay.jetty.Handler
        at public org.mortbay.jetty.Handler[] org.mortbay.jetty.handler.HandlerCollection.getHandlers()
        at org.mortbay.jetty.handler.HandlerCollection
        at org.mortbay.jetty.handler.ContextHandlerCollection
        at com.mprew.ec2.commons.server.LocalContextHandlerCollection
        at private com.mprew.ec2.commons.server.LocalContextHandlerCollection com.mprew.ec2.commons.services.jaxws_asm.SetLocalContextHandlerCollection.arg0
        at com.mprew.ec2.commons.services.jaxws_asm.SetLocalContextHandlerCollection,
    org.mortbay.jetty.Handler does not have a no-arg default constructor.]
    ....
    

    The does not have a no-arg default constructor seemed to me to be misleading. Maybe I wasn't understanding what the exception was saying. But it did indicate that there was a problem with my LocalContextHandlerCollection. I removed a dependency loop and the error cleared.

    Hopefully this will be helpful to others.

    0 讨论(0)
  • 2020-12-13 02:47

    I once received this message after thinking that putting @XmlTransient on a field I didn't need to serialize, in a class that was annotated with @XmlAccessorType(XmlAccessType.NONE).

    In that case, removing XmlTransient resolved the issue. I am not a JAXB expert, but I suspect that because AccessType.NONE indicates that no auto-serialization should be done (i.e. fields must be specifically annotated to serialize them) that makes XmlTransient illegal since its sole purpose is to exclude a field from auto-serialization.

    0 讨论(0)
  • 2020-12-13 02:52

    I had this same issue, I was passing a spring bean back as a ResponseBody object. When I handed back an object created by new, all was good.

    0 讨论(0)
  • 2020-12-13 02:52

    In my case, I was able to find the problem by temporarily catching the exception, descending into causes as needed (based on how deep the IllegalAnnotationException was), and calling getErrors() on it.

        try {
            // in my case, this was what gave me an exception
            endpoint.publish("/MyWebServicePort");
        // I got a WebServiceException caused by another exception, which was caused by the IllegalAnnotationsException
        } catch (WebServiceException e) {
            // Incidentally, I need to call getCause().getCause() on it, and cast to IllegalAnnotationsException before calling getErrors()
            System.err.println(((com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException)e.getCause().getCause()).getErrors());
        }
    
    0 讨论(0)
  • 2020-12-13 02:55

    This is happening be cause you have 2 classes with same name. For, example, I have 2 SOAP web-services named settings and settings2 both have the same class GetEmployee and this is ambiguous proving the error.

    0 讨论(0)
提交回复
热议问题