How to fix xmlMapper “Multiple fields representing property ”PS“” issue with Jaxb?How do I fix android.os.NetworkOnMainThreadException?Jaxb, Class has two properties of the same nameHow to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor versionHow to tell Jackson to ignore a field during serialization if its value is null?XML + Schema + Namespaces. No matching global declaration available for the validation rootRepresenting multiple element names in JAXBValidate xsd minOccurs elements C#Jackson XmlMapper XML to Json conversion issueHow to fix XmlMapper exception - java.lang.VerifyError: com.fasterxml.jackson?Import issues with XML file using XmlMapper

What does chmod -u do?

How can I write humor as character trait?

How can "mimic phobia" be cured or prevented?

Can I say "fingers" when referring to toes?

On a tidally locked planet, would time be quantized?

Hero deduces identity of a killer

14 year old daughter buying thongs

Why is so much work done on numerical verification of the Riemann Hypothesis?

How to explain what's wrong with this application of the chain rule?

It grows, but water kills it

Non-trope happy ending?

How does the math work for Perception checks?

A social experiment. What is the worst that can happen?

How to cover method return statement in Apex Class?

How do you make your own symbol when Detexify fails?

Pre-mixing cryogenic fuels and using only one fuel tank

Creepy dinosaur pc game identification

Angel of Condemnation - Exile creature with second ability

Moving brute-force search to FPGA

Why is it that I can sometimes guess the next note?

Redundant comparison & "if" before assignment

How should I respond when I lied about my education and the company finds out through background check?

Is this toilet slogan correct usage of the English language?

Can a stoichiometric mixture of oxygen and methane exist as a liquid at standard pressure and some (low) temperature?



How to fix xmlMapper “Multiple fields representing property ”PS“” issue with Jaxb?


How do I fix android.os.NetworkOnMainThreadException?Jaxb, Class has two properties of the same nameHow to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor versionHow to tell Jackson to ignore a field during serialization if its value is null?XML + Schema + Namespaces. No matching global declaration available for the validation rootRepresenting multiple element names in JAXBValidate xsd minOccurs elements C#Jackson XmlMapper XML to Json conversion issueHow to fix XmlMapper exception - java.lang.VerifyError: com.fasterxml.jackson?Import issues with XML file using XmlMapper













1















I used Jaxb to generate a Jar file from xsd:



CustomObject inputRequest = xmlMapper.readValue(input, CustomObject.class); 


The error message I am getting is:




com.fasterxml.jackson.databind.JsonMappingException: Multiple fields
representing property "PS": OrderLineType#pS vs OrderLineType#pSV5 at
[Source: (StringReader); line: 1, column: 1]




And my class is:



@XmlElement(name = "PS", namespace = "financetypes:defn:v4")
protected financetypes.v4.PSType pS;
@XmlElement(name = "PS", namespace = "financetypes:defn:v5")
protected financetypes.v5.PSType pSV5;


They have the same name, but different namespace.



Is xmlmapper able to handle XmlElement that has the same name and different namespace?



If yes, how do I fix this? If no, what should I do?



I am building jar file from jenkin. Is there a plugin that I can use to fix this issue?



Thanks!



here is my xsd
v4.xsd



 <!--Begin Definition: Complex Type: PriceStructureType-->
<xs:complexType name="PriceStructureType">
<xs:sequence>
<xs:element name="PriceModel" type="xs:string" minOccurs="0">
<xs:annotation>
<xs:documentation>
Will be required in future...
TODO: Add valid items...
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element ref="finance:SourceSystemPrice" minOccurs="0">
<xs:annotation>
<xs:documentation>
Will be required in future...
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="ComponentPrice" type="finance:ComponentListType" minOccurs="0">
<xs:annotation>
<xs:documentation>
Will be required in future...
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:element name="PriceStructure" type="finance:PriceStructureType"/>
<!--End Definition: Complex Type: PriceStructureType-->


v5.xsd



 <!--Begin Definition: Complex Type: PriceStructureType-->
<xs:complexType name="PriceStructureType">
<xs:sequence>
<xs:element name="PriceModel" type="xs:string" minOccurs="0">
<xs:annotation>
<xs:documentation>
Will be required in future...
TODO: Add valid items...
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element ref="finance:SourceSystemPrice" minOccurs="0">
<xs:annotation>
<xs:documentation>
Will be required in future...
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="ComponentPrice" type="finance:ComponentListType" minOccurs="0">
<xs:annotation>
<xs:documentation>
Will be required in future...
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:element name="PriceStructure" type="finance:PriceStructureType"/>
<!--End Definition: Complex Type: PriceStructureType-->


common.xsd



xmlns:finance="urn:financetypes:defn:v4"
xmlns:finance_v5="urn:financetypes:defn:v5"
<xs:import namespace="urn:financetypes:defn:v4" schemaLocation="financetypes.v4.xsd"/>
<xs:import namespace="urn:financetypes:defn:v5" schemaLocation="financetypes.v5.xsd"/>

<xs:choice>
<xs:element ref="finance:PriceStructure" minOccurs="0">
<xs:annotation>
<xs:documentation xml:lang="en">
Price Structure itemizes the price components of this OrderLine. Pricing
is a integral part of the Sales Order record.
This should be a required element for a sales order, but it is marked
as optional for backward compatibility.
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element ref="finance_v5:PriceStructure" minOccurs="0">
<xs:annotation>
<xs:documentation xml:lang="en">
Price Structure itemizes the price components of this OrderLine. Pricing
is a integral part of the Sales Order record.
This should be a required element for a sales order, but it is marked
as optional for backward compatibility.
</xs:documentation>
<xs:appinfo>
<jaxb:property name="PriceStructureV5"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:choice>









share|improve this question




























    1















    I used Jaxb to generate a Jar file from xsd:



    CustomObject inputRequest = xmlMapper.readValue(input, CustomObject.class); 


    The error message I am getting is:




    com.fasterxml.jackson.databind.JsonMappingException: Multiple fields
    representing property "PS": OrderLineType#pS vs OrderLineType#pSV5 at
    [Source: (StringReader); line: 1, column: 1]




    And my class is:



    @XmlElement(name = "PS", namespace = "financetypes:defn:v4")
    protected financetypes.v4.PSType pS;
    @XmlElement(name = "PS", namespace = "financetypes:defn:v5")
    protected financetypes.v5.PSType pSV5;


    They have the same name, but different namespace.



    Is xmlmapper able to handle XmlElement that has the same name and different namespace?



    If yes, how do I fix this? If no, what should I do?



    I am building jar file from jenkin. Is there a plugin that I can use to fix this issue?



    Thanks!



    here is my xsd
    v4.xsd



     <!--Begin Definition: Complex Type: PriceStructureType-->
    <xs:complexType name="PriceStructureType">
    <xs:sequence>
    <xs:element name="PriceModel" type="xs:string" minOccurs="0">
    <xs:annotation>
    <xs:documentation>
    Will be required in future...
    TODO: Add valid items...
    </xs:documentation>
    </xs:annotation>
    </xs:element>
    <xs:element ref="finance:SourceSystemPrice" minOccurs="0">
    <xs:annotation>
    <xs:documentation>
    Will be required in future...
    </xs:documentation>
    </xs:annotation>
    </xs:element>
    <xs:element name="ComponentPrice" type="finance:ComponentListType" minOccurs="0">
    <xs:annotation>
    <xs:documentation>
    Will be required in future...
    </xs:documentation>
    </xs:annotation>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    <xs:element name="PriceStructure" type="finance:PriceStructureType"/>
    <!--End Definition: Complex Type: PriceStructureType-->


    v5.xsd



     <!--Begin Definition: Complex Type: PriceStructureType-->
    <xs:complexType name="PriceStructureType">
    <xs:sequence>
    <xs:element name="PriceModel" type="xs:string" minOccurs="0">
    <xs:annotation>
    <xs:documentation>
    Will be required in future...
    TODO: Add valid items...
    </xs:documentation>
    </xs:annotation>
    </xs:element>
    <xs:element ref="finance:SourceSystemPrice" minOccurs="0">
    <xs:annotation>
    <xs:documentation>
    Will be required in future...
    </xs:documentation>
    </xs:annotation>
    </xs:element>
    <xs:element name="ComponentPrice" type="finance:ComponentListType" minOccurs="0">
    <xs:annotation>
    <xs:documentation>
    Will be required in future...
    </xs:documentation>
    </xs:annotation>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    <xs:element name="PriceStructure" type="finance:PriceStructureType"/>
    <!--End Definition: Complex Type: PriceStructureType-->


    common.xsd



    xmlns:finance="urn:financetypes:defn:v4"
    xmlns:finance_v5="urn:financetypes:defn:v5"
    <xs:import namespace="urn:financetypes:defn:v4" schemaLocation="financetypes.v4.xsd"/>
    <xs:import namespace="urn:financetypes:defn:v5" schemaLocation="financetypes.v5.xsd"/>

    <xs:choice>
    <xs:element ref="finance:PriceStructure" minOccurs="0">
    <xs:annotation>
    <xs:documentation xml:lang="en">
    Price Structure itemizes the price components of this OrderLine. Pricing
    is a integral part of the Sales Order record.
    This should be a required element for a sales order, but it is marked
    as optional for backward compatibility.
    </xs:documentation>
    </xs:annotation>
    </xs:element>
    <xs:element ref="finance_v5:PriceStructure" minOccurs="0">
    <xs:annotation>
    <xs:documentation xml:lang="en">
    Price Structure itemizes the price components of this OrderLine. Pricing
    is a integral part of the Sales Order record.
    This should be a required element for a sales order, but it is marked
    as optional for backward compatibility.
    </xs:documentation>
    <xs:appinfo>
    <jaxb:property name="PriceStructureV5"/>
    </xs:appinfo>
    </xs:annotation>
    </xs:element>
    </xs:choice>









    share|improve this question


























      1












      1








      1








      I used Jaxb to generate a Jar file from xsd:



      CustomObject inputRequest = xmlMapper.readValue(input, CustomObject.class); 


      The error message I am getting is:




      com.fasterxml.jackson.databind.JsonMappingException: Multiple fields
      representing property "PS": OrderLineType#pS vs OrderLineType#pSV5 at
      [Source: (StringReader); line: 1, column: 1]




      And my class is:



      @XmlElement(name = "PS", namespace = "financetypes:defn:v4")
      protected financetypes.v4.PSType pS;
      @XmlElement(name = "PS", namespace = "financetypes:defn:v5")
      protected financetypes.v5.PSType pSV5;


      They have the same name, but different namespace.



      Is xmlmapper able to handle XmlElement that has the same name and different namespace?



      If yes, how do I fix this? If no, what should I do?



      I am building jar file from jenkin. Is there a plugin that I can use to fix this issue?



      Thanks!



      here is my xsd
      v4.xsd



       <!--Begin Definition: Complex Type: PriceStructureType-->
      <xs:complexType name="PriceStructureType">
      <xs:sequence>
      <xs:element name="PriceModel" type="xs:string" minOccurs="0">
      <xs:annotation>
      <xs:documentation>
      Will be required in future...
      TODO: Add valid items...
      </xs:documentation>
      </xs:annotation>
      </xs:element>
      <xs:element ref="finance:SourceSystemPrice" minOccurs="0">
      <xs:annotation>
      <xs:documentation>
      Will be required in future...
      </xs:documentation>
      </xs:annotation>
      </xs:element>
      <xs:element name="ComponentPrice" type="finance:ComponentListType" minOccurs="0">
      <xs:annotation>
      <xs:documentation>
      Will be required in future...
      </xs:documentation>
      </xs:annotation>
      </xs:element>
      </xs:sequence>
      </xs:complexType>
      <xs:element name="PriceStructure" type="finance:PriceStructureType"/>
      <!--End Definition: Complex Type: PriceStructureType-->


      v5.xsd



       <!--Begin Definition: Complex Type: PriceStructureType-->
      <xs:complexType name="PriceStructureType">
      <xs:sequence>
      <xs:element name="PriceModel" type="xs:string" minOccurs="0">
      <xs:annotation>
      <xs:documentation>
      Will be required in future...
      TODO: Add valid items...
      </xs:documentation>
      </xs:annotation>
      </xs:element>
      <xs:element ref="finance:SourceSystemPrice" minOccurs="0">
      <xs:annotation>
      <xs:documentation>
      Will be required in future...
      </xs:documentation>
      </xs:annotation>
      </xs:element>
      <xs:element name="ComponentPrice" type="finance:ComponentListType" minOccurs="0">
      <xs:annotation>
      <xs:documentation>
      Will be required in future...
      </xs:documentation>
      </xs:annotation>
      </xs:element>
      </xs:sequence>
      </xs:complexType>
      <xs:element name="PriceStructure" type="finance:PriceStructureType"/>
      <!--End Definition: Complex Type: PriceStructureType-->


      common.xsd



      xmlns:finance="urn:financetypes:defn:v4"
      xmlns:finance_v5="urn:financetypes:defn:v5"
      <xs:import namespace="urn:financetypes:defn:v4" schemaLocation="financetypes.v4.xsd"/>
      <xs:import namespace="urn:financetypes:defn:v5" schemaLocation="financetypes.v5.xsd"/>

      <xs:choice>
      <xs:element ref="finance:PriceStructure" minOccurs="0">
      <xs:annotation>
      <xs:documentation xml:lang="en">
      Price Structure itemizes the price components of this OrderLine. Pricing
      is a integral part of the Sales Order record.
      This should be a required element for a sales order, but it is marked
      as optional for backward compatibility.
      </xs:documentation>
      </xs:annotation>
      </xs:element>
      <xs:element ref="finance_v5:PriceStructure" minOccurs="0">
      <xs:annotation>
      <xs:documentation xml:lang="en">
      Price Structure itemizes the price components of this OrderLine. Pricing
      is a integral part of the Sales Order record.
      This should be a required element for a sales order, but it is marked
      as optional for backward compatibility.
      </xs:documentation>
      <xs:appinfo>
      <jaxb:property name="PriceStructureV5"/>
      </xs:appinfo>
      </xs:annotation>
      </xs:element>
      </xs:choice>









      share|improve this question
















      I used Jaxb to generate a Jar file from xsd:



      CustomObject inputRequest = xmlMapper.readValue(input, CustomObject.class); 


      The error message I am getting is:




      com.fasterxml.jackson.databind.JsonMappingException: Multiple fields
      representing property "PS": OrderLineType#pS vs OrderLineType#pSV5 at
      [Source: (StringReader); line: 1, column: 1]




      And my class is:



      @XmlElement(name = "PS", namespace = "financetypes:defn:v4")
      protected financetypes.v4.PSType pS;
      @XmlElement(name = "PS", namespace = "financetypes:defn:v5")
      protected financetypes.v5.PSType pSV5;


      They have the same name, but different namespace.



      Is xmlmapper able to handle XmlElement that has the same name and different namespace?



      If yes, how do I fix this? If no, what should I do?



      I am building jar file from jenkin. Is there a plugin that I can use to fix this issue?



      Thanks!



      here is my xsd
      v4.xsd



       <!--Begin Definition: Complex Type: PriceStructureType-->
      <xs:complexType name="PriceStructureType">
      <xs:sequence>
      <xs:element name="PriceModel" type="xs:string" minOccurs="0">
      <xs:annotation>
      <xs:documentation>
      Will be required in future...
      TODO: Add valid items...
      </xs:documentation>
      </xs:annotation>
      </xs:element>
      <xs:element ref="finance:SourceSystemPrice" minOccurs="0">
      <xs:annotation>
      <xs:documentation>
      Will be required in future...
      </xs:documentation>
      </xs:annotation>
      </xs:element>
      <xs:element name="ComponentPrice" type="finance:ComponentListType" minOccurs="0">
      <xs:annotation>
      <xs:documentation>
      Will be required in future...
      </xs:documentation>
      </xs:annotation>
      </xs:element>
      </xs:sequence>
      </xs:complexType>
      <xs:element name="PriceStructure" type="finance:PriceStructureType"/>
      <!--End Definition: Complex Type: PriceStructureType-->


      v5.xsd



       <!--Begin Definition: Complex Type: PriceStructureType-->
      <xs:complexType name="PriceStructureType">
      <xs:sequence>
      <xs:element name="PriceModel" type="xs:string" minOccurs="0">
      <xs:annotation>
      <xs:documentation>
      Will be required in future...
      TODO: Add valid items...
      </xs:documentation>
      </xs:annotation>
      </xs:element>
      <xs:element ref="finance:SourceSystemPrice" minOccurs="0">
      <xs:annotation>
      <xs:documentation>
      Will be required in future...
      </xs:documentation>
      </xs:annotation>
      </xs:element>
      <xs:element name="ComponentPrice" type="finance:ComponentListType" minOccurs="0">
      <xs:annotation>
      <xs:documentation>
      Will be required in future...
      </xs:documentation>
      </xs:annotation>
      </xs:element>
      </xs:sequence>
      </xs:complexType>
      <xs:element name="PriceStructure" type="finance:PriceStructureType"/>
      <!--End Definition: Complex Type: PriceStructureType-->


      common.xsd



      xmlns:finance="urn:financetypes:defn:v4"
      xmlns:finance_v5="urn:financetypes:defn:v5"
      <xs:import namespace="urn:financetypes:defn:v4" schemaLocation="financetypes.v4.xsd"/>
      <xs:import namespace="urn:financetypes:defn:v5" schemaLocation="financetypes.v5.xsd"/>

      <xs:choice>
      <xs:element ref="finance:PriceStructure" minOccurs="0">
      <xs:annotation>
      <xs:documentation xml:lang="en">
      Price Structure itemizes the price components of this OrderLine. Pricing
      is a integral part of the Sales Order record.
      This should be a required element for a sales order, but it is marked
      as optional for backward compatibility.
      </xs:documentation>
      </xs:annotation>
      </xs:element>
      <xs:element ref="finance_v5:PriceStructure" minOccurs="0">
      <xs:annotation>
      <xs:documentation xml:lang="en">
      Price Structure itemizes the price components of this OrderLine. Pricing
      is a integral part of the Sales Order record.
      This should be a required element for a sales order, but it is marked
      as optional for backward compatibility.
      </xs:documentation>
      <xs:appinfo>
      <jaxb:property name="PriceStructureV5"/>
      </xs:appinfo>
      </xs:annotation>
      </xs:element>
      </xs:choice>






      java xml jackson jaxb xmlmapper






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 18:30







      Aodirary

















      asked Mar 7 at 6:25









      AodiraryAodirary

      85




      85






















          1 Answer
          1






          active

          oldest

          votes


















          2














          You could do this. For a root class containing these 2 elements:



          @XmlRootElement(name = "root")
          @XmlAccessorType(XmlAccessType.FIELD)
          public class Root

          @XmlElement(name = "PS", namespace = "financetypes:defn:v4")
          protected financetypes.v4.PSType pS;
          @XmlElement(name = "PS", namespace = "financetypes:defn:v5")
          protected financetypes.v5.PSType pSV5;



          You can create you classes with the different versions like this:



          @XmlAccessorType(XmlAccessType.FIELD)
          @XmlType(name = "v4PS", namespace = "financetypes:defn:v4")
          public class PSType

          @XmlValue
          private String value;



          and:



          @XmlAccessorType(XmlAccessType.FIELD)
          @XmlType(name = "v5PS", namespace = "financetypes:defn:v5")
          public class PSType

          @XmlValue
          private String value;



          For a sample xml as below:



          <root xmlns:v4="financetypes:defn:v4" xmlns:v5="financetypes:defn:v5">
          <v4:PS>version 4</v4:PS>
          <v5:PS>version 5</v5:PS>
          </root>


          You will be able to unmarshall properly.



          Update to respond to the comment:



          You use xsd to generate the classes. You did not provide the xsd so I will assume you are not allowed to. I created an xsd to generate the classes you show in your question. The namespace.xsd looks like this:



          <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:v4="financetypes:defn:v4" xmlns:v5="financetypes:defn:v5">

          <xs:element name="root">
          <xs:complexType>
          <xs:all>
          <xs:element name="v4PSType" type="PSTypev4" />
          <xs:element name="v5PSType" type="PSTypev5" />
          </xs:all>
          </xs:complexType>
          </xs:element>

          <xs:complexType name="PSTypev4">
          <xs:simpleContent>
          <xs:extension base="xs:string" />
          </xs:simpleContent>
          </xs:complexType>

          <xs:complexType name="PSTypev5">
          <xs:simpleContent>
          <xs:extension base="xs:string" />
          </xs:simpleContent>
          </xs:complexType>

          </xs:schema>


          Then your bindings would be:



          <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
          <jaxb:bindings version="2.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
          xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
          xmlns:annox="http://annox.dev.java.net"
          jaxb:extensionBindingPrefixes="xjc">

          <jaxb:bindings schemaLocation="../xsd/namespaces.xsd">
          <jaxb:bindings node="//xs:complexType[@name='PSTypev4']">
          <annox:annotate target = "class">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlType" name="v4PSType" namespace="financetypes:defn:v4" />
          </annox:annotate>
          </jaxb:bindings>

          <jaxb:bindings node="//xs:complexType[@name='PSTypev5']">
          <annox:annotate target = "class">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlType" name="v5PSType" namespace="financetypes:defn:v5" />
          </annox:annotate>
          </jaxb:bindings>

          <jaxb:bindings node="//xs:element[@name='root']//xs:complexType//xs:all//xs:element[@name='v5PSType']">
          <annox:annotate target = "field">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlElement" name="PS" namespace="financetypes:defn:v5" />
          </annox:annotate>
          </jaxb:bindings>

          <jaxb:bindings node="//xs:element[@name='root']//xs:complexType//xs:all//xs:element[@name='v4PSType']">
          <annox:annotate target = "field">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlElement" name="PS" namespace="financetypes:defn:v4" />
          </annox:annotate>
          </jaxb:bindings>
          </jaxb:bindings>
          </jaxb:bindings>


          And then you would end up with classes as those in my answer.






          share|improve this answer

























          • Class is generated by jenkin. How do I modify then during building stage?

            – Aodirary
            Mar 7 at 16:20











          • @Aodirary How? Do you have some xsds and you run a maven plugin to generate the classes in your Jenkins job?

            – mart
            Mar 7 at 20:19












          • Yes. I have some xsds that is stastic and I run a maven plugin to generate the classes in build.gradle

            – Aodirary
            Mar 7 at 20:50











          • @Aodirary you can use bindings to add the annotation then. Can you paste me a sample of your xsd?

            – mart
            Mar 7 at 21:31











          • How do I use bindings to add the annotation?

            – Aodirary
            Mar 8 at 7:45










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037312%2fhow-to-fix-xmlmapper-multiple-fields-representing-property-ps-issue-with-jax%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          You could do this. For a root class containing these 2 elements:



          @XmlRootElement(name = "root")
          @XmlAccessorType(XmlAccessType.FIELD)
          public class Root

          @XmlElement(name = "PS", namespace = "financetypes:defn:v4")
          protected financetypes.v4.PSType pS;
          @XmlElement(name = "PS", namespace = "financetypes:defn:v5")
          protected financetypes.v5.PSType pSV5;



          You can create you classes with the different versions like this:



          @XmlAccessorType(XmlAccessType.FIELD)
          @XmlType(name = "v4PS", namespace = "financetypes:defn:v4")
          public class PSType

          @XmlValue
          private String value;



          and:



          @XmlAccessorType(XmlAccessType.FIELD)
          @XmlType(name = "v5PS", namespace = "financetypes:defn:v5")
          public class PSType

          @XmlValue
          private String value;



          For a sample xml as below:



          <root xmlns:v4="financetypes:defn:v4" xmlns:v5="financetypes:defn:v5">
          <v4:PS>version 4</v4:PS>
          <v5:PS>version 5</v5:PS>
          </root>


          You will be able to unmarshall properly.



          Update to respond to the comment:



          You use xsd to generate the classes. You did not provide the xsd so I will assume you are not allowed to. I created an xsd to generate the classes you show in your question. The namespace.xsd looks like this:



          <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:v4="financetypes:defn:v4" xmlns:v5="financetypes:defn:v5">

          <xs:element name="root">
          <xs:complexType>
          <xs:all>
          <xs:element name="v4PSType" type="PSTypev4" />
          <xs:element name="v5PSType" type="PSTypev5" />
          </xs:all>
          </xs:complexType>
          </xs:element>

          <xs:complexType name="PSTypev4">
          <xs:simpleContent>
          <xs:extension base="xs:string" />
          </xs:simpleContent>
          </xs:complexType>

          <xs:complexType name="PSTypev5">
          <xs:simpleContent>
          <xs:extension base="xs:string" />
          </xs:simpleContent>
          </xs:complexType>

          </xs:schema>


          Then your bindings would be:



          <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
          <jaxb:bindings version="2.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
          xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
          xmlns:annox="http://annox.dev.java.net"
          jaxb:extensionBindingPrefixes="xjc">

          <jaxb:bindings schemaLocation="../xsd/namespaces.xsd">
          <jaxb:bindings node="//xs:complexType[@name='PSTypev4']">
          <annox:annotate target = "class">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlType" name="v4PSType" namespace="financetypes:defn:v4" />
          </annox:annotate>
          </jaxb:bindings>

          <jaxb:bindings node="//xs:complexType[@name='PSTypev5']">
          <annox:annotate target = "class">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlType" name="v5PSType" namespace="financetypes:defn:v5" />
          </annox:annotate>
          </jaxb:bindings>

          <jaxb:bindings node="//xs:element[@name='root']//xs:complexType//xs:all//xs:element[@name='v5PSType']">
          <annox:annotate target = "field">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlElement" name="PS" namespace="financetypes:defn:v5" />
          </annox:annotate>
          </jaxb:bindings>

          <jaxb:bindings node="//xs:element[@name='root']//xs:complexType//xs:all//xs:element[@name='v4PSType']">
          <annox:annotate target = "field">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlElement" name="PS" namespace="financetypes:defn:v4" />
          </annox:annotate>
          </jaxb:bindings>
          </jaxb:bindings>
          </jaxb:bindings>


          And then you would end up with classes as those in my answer.






          share|improve this answer

























          • Class is generated by jenkin. How do I modify then during building stage?

            – Aodirary
            Mar 7 at 16:20











          • @Aodirary How? Do you have some xsds and you run a maven plugin to generate the classes in your Jenkins job?

            – mart
            Mar 7 at 20:19












          • Yes. I have some xsds that is stastic and I run a maven plugin to generate the classes in build.gradle

            – Aodirary
            Mar 7 at 20:50











          • @Aodirary you can use bindings to add the annotation then. Can you paste me a sample of your xsd?

            – mart
            Mar 7 at 21:31











          • How do I use bindings to add the annotation?

            – Aodirary
            Mar 8 at 7:45















          2














          You could do this. For a root class containing these 2 elements:



          @XmlRootElement(name = "root")
          @XmlAccessorType(XmlAccessType.FIELD)
          public class Root

          @XmlElement(name = "PS", namespace = "financetypes:defn:v4")
          protected financetypes.v4.PSType pS;
          @XmlElement(name = "PS", namespace = "financetypes:defn:v5")
          protected financetypes.v5.PSType pSV5;



          You can create you classes with the different versions like this:



          @XmlAccessorType(XmlAccessType.FIELD)
          @XmlType(name = "v4PS", namespace = "financetypes:defn:v4")
          public class PSType

          @XmlValue
          private String value;



          and:



          @XmlAccessorType(XmlAccessType.FIELD)
          @XmlType(name = "v5PS", namespace = "financetypes:defn:v5")
          public class PSType

          @XmlValue
          private String value;



          For a sample xml as below:



          <root xmlns:v4="financetypes:defn:v4" xmlns:v5="financetypes:defn:v5">
          <v4:PS>version 4</v4:PS>
          <v5:PS>version 5</v5:PS>
          </root>


          You will be able to unmarshall properly.



          Update to respond to the comment:



          You use xsd to generate the classes. You did not provide the xsd so I will assume you are not allowed to. I created an xsd to generate the classes you show in your question. The namespace.xsd looks like this:



          <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:v4="financetypes:defn:v4" xmlns:v5="financetypes:defn:v5">

          <xs:element name="root">
          <xs:complexType>
          <xs:all>
          <xs:element name="v4PSType" type="PSTypev4" />
          <xs:element name="v5PSType" type="PSTypev5" />
          </xs:all>
          </xs:complexType>
          </xs:element>

          <xs:complexType name="PSTypev4">
          <xs:simpleContent>
          <xs:extension base="xs:string" />
          </xs:simpleContent>
          </xs:complexType>

          <xs:complexType name="PSTypev5">
          <xs:simpleContent>
          <xs:extension base="xs:string" />
          </xs:simpleContent>
          </xs:complexType>

          </xs:schema>


          Then your bindings would be:



          <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
          <jaxb:bindings version="2.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
          xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
          xmlns:annox="http://annox.dev.java.net"
          jaxb:extensionBindingPrefixes="xjc">

          <jaxb:bindings schemaLocation="../xsd/namespaces.xsd">
          <jaxb:bindings node="//xs:complexType[@name='PSTypev4']">
          <annox:annotate target = "class">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlType" name="v4PSType" namespace="financetypes:defn:v4" />
          </annox:annotate>
          </jaxb:bindings>

          <jaxb:bindings node="//xs:complexType[@name='PSTypev5']">
          <annox:annotate target = "class">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlType" name="v5PSType" namespace="financetypes:defn:v5" />
          </annox:annotate>
          </jaxb:bindings>

          <jaxb:bindings node="//xs:element[@name='root']//xs:complexType//xs:all//xs:element[@name='v5PSType']">
          <annox:annotate target = "field">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlElement" name="PS" namespace="financetypes:defn:v5" />
          </annox:annotate>
          </jaxb:bindings>

          <jaxb:bindings node="//xs:element[@name='root']//xs:complexType//xs:all//xs:element[@name='v4PSType']">
          <annox:annotate target = "field">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlElement" name="PS" namespace="financetypes:defn:v4" />
          </annox:annotate>
          </jaxb:bindings>
          </jaxb:bindings>
          </jaxb:bindings>


          And then you would end up with classes as those in my answer.






          share|improve this answer

























          • Class is generated by jenkin. How do I modify then during building stage?

            – Aodirary
            Mar 7 at 16:20











          • @Aodirary How? Do you have some xsds and you run a maven plugin to generate the classes in your Jenkins job?

            – mart
            Mar 7 at 20:19












          • Yes. I have some xsds that is stastic and I run a maven plugin to generate the classes in build.gradle

            – Aodirary
            Mar 7 at 20:50











          • @Aodirary you can use bindings to add the annotation then. Can you paste me a sample of your xsd?

            – mart
            Mar 7 at 21:31











          • How do I use bindings to add the annotation?

            – Aodirary
            Mar 8 at 7:45













          2












          2








          2







          You could do this. For a root class containing these 2 elements:



          @XmlRootElement(name = "root")
          @XmlAccessorType(XmlAccessType.FIELD)
          public class Root

          @XmlElement(name = "PS", namespace = "financetypes:defn:v4")
          protected financetypes.v4.PSType pS;
          @XmlElement(name = "PS", namespace = "financetypes:defn:v5")
          protected financetypes.v5.PSType pSV5;



          You can create you classes with the different versions like this:



          @XmlAccessorType(XmlAccessType.FIELD)
          @XmlType(name = "v4PS", namespace = "financetypes:defn:v4")
          public class PSType

          @XmlValue
          private String value;



          and:



          @XmlAccessorType(XmlAccessType.FIELD)
          @XmlType(name = "v5PS", namespace = "financetypes:defn:v5")
          public class PSType

          @XmlValue
          private String value;



          For a sample xml as below:



          <root xmlns:v4="financetypes:defn:v4" xmlns:v5="financetypes:defn:v5">
          <v4:PS>version 4</v4:PS>
          <v5:PS>version 5</v5:PS>
          </root>


          You will be able to unmarshall properly.



          Update to respond to the comment:



          You use xsd to generate the classes. You did not provide the xsd so I will assume you are not allowed to. I created an xsd to generate the classes you show in your question. The namespace.xsd looks like this:



          <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:v4="financetypes:defn:v4" xmlns:v5="financetypes:defn:v5">

          <xs:element name="root">
          <xs:complexType>
          <xs:all>
          <xs:element name="v4PSType" type="PSTypev4" />
          <xs:element name="v5PSType" type="PSTypev5" />
          </xs:all>
          </xs:complexType>
          </xs:element>

          <xs:complexType name="PSTypev4">
          <xs:simpleContent>
          <xs:extension base="xs:string" />
          </xs:simpleContent>
          </xs:complexType>

          <xs:complexType name="PSTypev5">
          <xs:simpleContent>
          <xs:extension base="xs:string" />
          </xs:simpleContent>
          </xs:complexType>

          </xs:schema>


          Then your bindings would be:



          <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
          <jaxb:bindings version="2.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
          xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
          xmlns:annox="http://annox.dev.java.net"
          jaxb:extensionBindingPrefixes="xjc">

          <jaxb:bindings schemaLocation="../xsd/namespaces.xsd">
          <jaxb:bindings node="//xs:complexType[@name='PSTypev4']">
          <annox:annotate target = "class">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlType" name="v4PSType" namespace="financetypes:defn:v4" />
          </annox:annotate>
          </jaxb:bindings>

          <jaxb:bindings node="//xs:complexType[@name='PSTypev5']">
          <annox:annotate target = "class">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlType" name="v5PSType" namespace="financetypes:defn:v5" />
          </annox:annotate>
          </jaxb:bindings>

          <jaxb:bindings node="//xs:element[@name='root']//xs:complexType//xs:all//xs:element[@name='v5PSType']">
          <annox:annotate target = "field">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlElement" name="PS" namespace="financetypes:defn:v5" />
          </annox:annotate>
          </jaxb:bindings>

          <jaxb:bindings node="//xs:element[@name='root']//xs:complexType//xs:all//xs:element[@name='v4PSType']">
          <annox:annotate target = "field">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlElement" name="PS" namespace="financetypes:defn:v4" />
          </annox:annotate>
          </jaxb:bindings>
          </jaxb:bindings>
          </jaxb:bindings>


          And then you would end up with classes as those in my answer.






          share|improve this answer















          You could do this. For a root class containing these 2 elements:



          @XmlRootElement(name = "root")
          @XmlAccessorType(XmlAccessType.FIELD)
          public class Root

          @XmlElement(name = "PS", namespace = "financetypes:defn:v4")
          protected financetypes.v4.PSType pS;
          @XmlElement(name = "PS", namespace = "financetypes:defn:v5")
          protected financetypes.v5.PSType pSV5;



          You can create you classes with the different versions like this:



          @XmlAccessorType(XmlAccessType.FIELD)
          @XmlType(name = "v4PS", namespace = "financetypes:defn:v4")
          public class PSType

          @XmlValue
          private String value;



          and:



          @XmlAccessorType(XmlAccessType.FIELD)
          @XmlType(name = "v5PS", namespace = "financetypes:defn:v5")
          public class PSType

          @XmlValue
          private String value;



          For a sample xml as below:



          <root xmlns:v4="financetypes:defn:v4" xmlns:v5="financetypes:defn:v5">
          <v4:PS>version 4</v4:PS>
          <v5:PS>version 5</v5:PS>
          </root>


          You will be able to unmarshall properly.



          Update to respond to the comment:



          You use xsd to generate the classes. You did not provide the xsd so I will assume you are not allowed to. I created an xsd to generate the classes you show in your question. The namespace.xsd looks like this:



          <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:v4="financetypes:defn:v4" xmlns:v5="financetypes:defn:v5">

          <xs:element name="root">
          <xs:complexType>
          <xs:all>
          <xs:element name="v4PSType" type="PSTypev4" />
          <xs:element name="v5PSType" type="PSTypev5" />
          </xs:all>
          </xs:complexType>
          </xs:element>

          <xs:complexType name="PSTypev4">
          <xs:simpleContent>
          <xs:extension base="xs:string" />
          </xs:simpleContent>
          </xs:complexType>

          <xs:complexType name="PSTypev5">
          <xs:simpleContent>
          <xs:extension base="xs:string" />
          </xs:simpleContent>
          </xs:complexType>

          </xs:schema>


          Then your bindings would be:



          <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
          <jaxb:bindings version="2.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
          xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
          xmlns:annox="http://annox.dev.java.net"
          jaxb:extensionBindingPrefixes="xjc">

          <jaxb:bindings schemaLocation="../xsd/namespaces.xsd">
          <jaxb:bindings node="//xs:complexType[@name='PSTypev4']">
          <annox:annotate target = "class">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlType" name="v4PSType" namespace="financetypes:defn:v4" />
          </annox:annotate>
          </jaxb:bindings>

          <jaxb:bindings node="//xs:complexType[@name='PSTypev5']">
          <annox:annotate target = "class">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlType" name="v5PSType" namespace="financetypes:defn:v5" />
          </annox:annotate>
          </jaxb:bindings>

          <jaxb:bindings node="//xs:element[@name='root']//xs:complexType//xs:all//xs:element[@name='v5PSType']">
          <annox:annotate target = "field">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlElement" name="PS" namespace="financetypes:defn:v5" />
          </annox:annotate>
          </jaxb:bindings>

          <jaxb:bindings node="//xs:element[@name='root']//xs:complexType//xs:all//xs:element[@name='v4PSType']">
          <annox:annotate target = "field">
          <annox:annotate annox:class="javax.xml.bind.annotation.XmlElement" name="PS" namespace="financetypes:defn:v4" />
          </annox:annotate>
          </jaxb:bindings>
          </jaxb:bindings>
          </jaxb:bindings>


          And then you would end up with classes as those in my answer.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 8 at 9:18

























          answered Mar 7 at 8:24









          martmart

          1,932157




          1,932157












          • Class is generated by jenkin. How do I modify then during building stage?

            – Aodirary
            Mar 7 at 16:20











          • @Aodirary How? Do you have some xsds and you run a maven plugin to generate the classes in your Jenkins job?

            – mart
            Mar 7 at 20:19












          • Yes. I have some xsds that is stastic and I run a maven plugin to generate the classes in build.gradle

            – Aodirary
            Mar 7 at 20:50











          • @Aodirary you can use bindings to add the annotation then. Can you paste me a sample of your xsd?

            – mart
            Mar 7 at 21:31











          • How do I use bindings to add the annotation?

            – Aodirary
            Mar 8 at 7:45

















          • Class is generated by jenkin. How do I modify then during building stage?

            – Aodirary
            Mar 7 at 16:20











          • @Aodirary How? Do you have some xsds and you run a maven plugin to generate the classes in your Jenkins job?

            – mart
            Mar 7 at 20:19












          • Yes. I have some xsds that is stastic and I run a maven plugin to generate the classes in build.gradle

            – Aodirary
            Mar 7 at 20:50











          • @Aodirary you can use bindings to add the annotation then. Can you paste me a sample of your xsd?

            – mart
            Mar 7 at 21:31











          • How do I use bindings to add the annotation?

            – Aodirary
            Mar 8 at 7:45
















          Class is generated by jenkin. How do I modify then during building stage?

          – Aodirary
          Mar 7 at 16:20





          Class is generated by jenkin. How do I modify then during building stage?

          – Aodirary
          Mar 7 at 16:20













          @Aodirary How? Do you have some xsds and you run a maven plugin to generate the classes in your Jenkins job?

          – mart
          Mar 7 at 20:19






          @Aodirary How? Do you have some xsds and you run a maven plugin to generate the classes in your Jenkins job?

          – mart
          Mar 7 at 20:19














          Yes. I have some xsds that is stastic and I run a maven plugin to generate the classes in build.gradle

          – Aodirary
          Mar 7 at 20:50





          Yes. I have some xsds that is stastic and I run a maven plugin to generate the classes in build.gradle

          – Aodirary
          Mar 7 at 20:50













          @Aodirary you can use bindings to add the annotation then. Can you paste me a sample of your xsd?

          – mart
          Mar 7 at 21:31





          @Aodirary you can use bindings to add the annotation then. Can you paste me a sample of your xsd?

          – mart
          Mar 7 at 21:31













          How do I use bindings to add the annotation?

          – Aodirary
          Mar 8 at 7:45





          How do I use bindings to add the annotation?

          – Aodirary
          Mar 8 at 7:45



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037312%2fhow-to-fix-xmlmapper-multiple-fields-representing-property-ps-issue-with-jax%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          1928 у кіно

          Захаров Федір Захарович

          Ель Греко