com sun xml internal bind v2 runtime IllegalAnnotationsException

com sun xml internal bind v2 runtime IllegalAnnotationsException

com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions

com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
Class has two properties of the same name "addressList"
    this problem is related to the following location:
        at public java.util.List com.javahonk.bean.Person.getAddressList()
        at com.javahonk.bean.Person
        at private java.util.List com.javahonk.bean.Persons.persons
        at com.javahonk.bean.Persons
    this problem is related to the following location:
        at java.util.List com.javahonk.bean.Person.addressList
        at com.javahonk.bean.Person
        at private java.util.List com.javahonk.bean.Persons.persons
        at com.javahonk.bean.Persons
Class has two properties of the same name "id"
    this problem is related to the following location:
        at public java.lang.String com.javahonk.bean.Person.getId()
        at com.javahonk.bean.Person
        at private java.util.List com.javahonk.bean.Persons.persons
        at com.javahonk.bean.Persons
    this problem is related to the following location:
        at private java.lang.String com.javahonk.bean.Person.id
        at com.javahonk.bean.Person
        at private java.util.List com.javahonk.bean.Persons.persons
        at com.javahonk.bean.Persons

    at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:91)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:451)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:283)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:126)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1142)
    at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:130)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:248)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:235)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:445)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:637)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:584)
    at com.javahonk.XMLToJavaJAXB.main(XMLToJavaJAXB.java:21)

Solution: If you are working with JAXB and getting above exception it means java object annotation has not been set properly. Usually this exception can be fixed using XmlAccessorType annotation as shown below on top of the class:

@XmlAccessorType(XmlAccessType.FIELD)
public class Person {

Please see full example to understand and fix the issue: how to convert XML to java or Java to XML in this post

For more information about JAXB please see Oracle JAXB tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *