PersistenceException - duplicate name annotation in Simple XML deserialization

I am testing a simple xml tutorial from this. I am changing the xml file as follows.

<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 encoding to the class Example7.

   @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.

Thank.

0
source share
1 answer

You need to annotate your field xin your class Example7in order 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 relevant section of the Simple XML tutorial .

0
source

Source: https://habr.com/ru/post/1545247/


All Articles