最近项目组要用到xml与object的转换,我找到了jaxb2。
但是遇到一个问题,就是在pojo类中添加getter方法后会报错:
Exception in thread "main" com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 5 counts of IllegalAnnotationExceptions
Class has two properties of the same name "gender"
this problem is related to the following location:
at public java.lang.String entity.Teacher.getGender()
at entity.Teacher
this problem is related to the following location:
at private java.lang.String entity.Teacher.gender
at entity.Teacher
Class has two properties of the same name "name"
this problem is related to the following location:
at public java.lang.String entity.Teacher.getName()
at entity.Teacher
this problem is related to the following location:
at private java.lang.String entity.Teacher.name
at entity.Teacher
Class has two properties of the same name "students"
this problem is related to the following location:
at public java.util.Set entity.Teacher.getStudents()
at entity.Teacher
this problem is related to the following location:
at private java.util.Set entity.Teacher.students
at entity.Teacher
Class has two properties of the same name "gender"
this problem is related to the following location:
at public java.lang.String entity.Student.getGender()
at entity.Student
at private java.util.Set entity.Teacher.students
at entity.Teacher
this problem is related to the following location:
at private java.lang.String entity.Student.gender
at entity.Student
at private java.util.Set entity.Teacher.students
at entity.Teacher
Class has two properties of the same name "name"
this problem is related to the following location:
at public java.lang.String entity.Student.getName()
at entity.Student
at private java.util.Set entity.Teacher.students
at entity.Teacher
this problem is related to the following location:
at private java.lang.String entity.Student.name
at entity.Student
at private java.util.Set entity.Teacher.students
at entity.Teacher at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.find(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at test.Test.main(Test.java:19)