Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IllegalAnnotationsException: Class has two properties of same name

I am trying to develop a IBM JAX_WS web service using RSA 7.5 and Websphere 7 server. Since I am a beginner, hence I am following Java-class first approach i.e. I am creating the Java classes first and then generating the WSDL file.

When i try to create the wsdl file, i am getting an exception:

java.security.PrivilegedActionException:com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationsException Class has two properties of the same name "planId"

My class refered here looks something like this:

public class MemberDetails{
    @XMLElement(required=true)
    private String planId;
    //public getters and setters for the planId;
}

I dont have any idea like why is this exception happening. Via Google search I tried a few alternatives to resolve it but none of them worked for me :(

Note:

This is the only annotation I am using throughout my workspace. I am not sure if this is dependent on some other annotations or not. But I tried with a few such as @XMLElement(name="Plan",required=true), @XMLType, etc but every time I am getting this exception.

This exception is occuring during wsgen. (java.lang.reflect.InvocationTargetException)

EDIT

Basically, when we create a wsdl from java service method and open that WSDL in SOAP UI, then we get <!--Optional--> at the top of every element. I want to remove this option tag <!--Optional--> tag, hence I am trying for @XMLElement(required=true) approach so that when I open the WSDL in SOAP UI <!--Optional--> does not appears for compulsary elements.

According to my concept, @XMLElement(required=true) will set the minOccurs to 1 i.e. greater than zero and hence the optional comment will be removed from WSDL when I open it in SOAP UI. But Unfortunately its not working hence my concept is incorrect. After the WSDL is generated, I can see that the minOccurs is still 0.

Please explain how can I remove the optional tag when I open the WSDL in SOAP UI.

Regards,

like image 915
user182944 Avatar asked Sep 12 '12 16:09

user182944


1 Answers

By default JAXB (JSR-222) implementations process public accessor methods and annotated fields. If you annotate a field that you also have get/set methods for you will get this exception:

If you are going to annotate fields then you should specify @XmlAccessorType(XmlAccessType.FIELD)

@XmlAccessorType(XmlAccessType.FIELD)
public class MemberDetails{
    @XMLElement(required=true)
    private String planId;
    //public getters and setters for the planId;
}

Or you can annotate the property

public class MemberDetails{

    private String planId;

    @XMLElement(required=true)
    public String getPlanId() {
        return planId;
    }
}

For More Information

  • http://blog.bdoughan.com/2011/06/using-jaxbs-xmlaccessortype-to.html
like image 143
bdoughan Avatar answered Oct 01 '22 01:10

bdoughan