PersistenceException -Duplicate annotation of name in Simple XML deserialization

拜拜、爱过 提交于 2019-12-11 22:00:14

问题


I test simple xml tutorial from this link. I change the xml file like this.

<example xmlns:ns1="http://www.blah.com/ns/a">
  <a>
    <b>
        <x>abc</x>
      <ns1:x>blah</ns1:x>
    </b>
  </a>
</example>

and I add the following coding into the Example7 class.

   @Path("a/b")
   @Element(name = "x")
   private String x_;

I got this exception PersistenceException : Duplicate annotation of name 'x' on field 'x'. I would like to know how to overcome this exception.

Thanks.


回答1:


You need to annotate your field x within your class Example7 to use the namespace ns1.

@Element
@Path("a/b")
@Namespace(reference="http://www.blah.com/ns/a", prefix="ns1")
private String x;

Also see the corresponding section of Simple XML tutorial.



来源:https://stackoverflow.com/questions/19153953/persistenceexception-duplicate-annotation-of-name-in-simple-xml-deserialization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!