How to fix xmlMapper “Multiple fields representing property ”PS“” issue with Jaxb?2019 Community Moderator ElectionHow 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
Was it really inappropriate to write a pull request for the company I interviewed with?
What is the cause of the Apocalypse in The Umbrella Academy?
Recommendation letter by significant other if you worked with them professionally?
Virginia employer terminated employee and wants signing bonus returned
They call me Inspector Morse
I reported the illegal activity of my boss to his boss. My boss found out. Now I am being punished. What should I do?
IBM PAT Number Sequence
When a wind turbine does not produce enough electricity how does the power company compensate for the loss?
How strictly should I take "Candidates must be local"?
What does "promotional consideration" at the end credits mean?
Find longest word in a string: are any of these algorithms good?
When traveling to Europe from the US, do I need to purchase a different power strip?
What wound would be of little consequence to a biped but terrible for a quadruped?
How does NOW work?
How can I ensure my trip to the UK will not have to be cancelled because of Brexit?
'The literal of type int is out of range' con número enteros pequeños (2 dígitos)
Reverse string, can I make it faster?
Examples of a statistic that is not independent of sample's distribution?
What was the implant device Captain Marvel was using?
In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?
Latex does not go to next line
Hotkey (or other quick way) to insert a keyframe for only one component of a vector-valued property?
How to secure an aircraft at a transient parking space?
Is this Paypal Github SDK reference really a dangerous site?
How to fix xmlMapper “Multiple fields representing property ”PS“” issue with Jaxb?
2019 Community Moderator ElectionHow 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
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
New contributor
Aodirary is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
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
New contributor
Aodirary is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
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
New contributor
Aodirary is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
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
java xml jackson jaxb xmlmapper
New contributor
Aodirary is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Aodirary is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Mar 8 at 18:30
Aodirary
New contributor
Aodirary is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Mar 7 at 6:25
AodiraryAodirary
84
84
New contributor
Aodirary is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Aodirary is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Aodirary is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
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
|
show 14 more comments
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
);
);
Aodirary is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
|
show 14 more comments
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.
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
|
show 14 more comments
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.
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.
edited Mar 8 at 9:18
answered Mar 7 at 8:24
martmart
1,842157
1,842157
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
|
show 14 more comments
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
|
show 14 more comments
Aodirary is a new contributor. Be nice, and check out our Code of Conduct.
Aodirary is a new contributor. Be nice, and check out our Code of Conduct.
Aodirary is a new contributor. Be nice, and check out our Code of Conduct.
Aodirary is a new contributor. Be nice, and check out our Code of Conduct.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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