jaxb2

Jaxb 2 mapping different element to the same property

六眼飞鱼酱① 提交于 2019-12-23 03:05:17
问题 I wonder if this is possible in jaxb2. I have a xml that can be either < element > or < element2 > it will never apear at the some time. They are both of type String and I want it to map to the same property in my java class. Is there a way in jaxb2 to configure that? Thanks Charlie 回答1: What would happen if you tried to serialize back to XML? Which element name would be used? Assuming you only need to deserialize from XML to Java, then you can do this by annotating your setter methods

JAXB - marshal java object with XML string field

风流意气都作罢 提交于 2019-12-23 01:25:13
问题 suppose i have an object with String property that has an XML string. like: class myObject { String xml; @XmlElement(name = "xml", type = String.class) public String getXml() { return xml; } public void setXml(String xml) { this.xml = xml; } } i set an XML String to this property - such as myObject.setXml("<xml>bbb</xml>"); now i want to marshal it using JAXB and i get: <xml><xml>bbb</xml></xml> where i want to get <xml>bbb</xml> how can i do it? EDIT: the problem is that String xml, stores a

how to map a bean structure to a different schema with jax-rs

大城市里の小女人 提交于 2019-12-23 00:46:31
问题 I have this bean @XmlRootElement class Test { boolean someValue; List<Field> fields; } I would like to serialize it as <fields> <field> <name>someValue</name> <value>...</value> </field> </fields> <fields> <field> <name>otherValue</name> <value>...</value> </field> </fields> (or as json) How should I do that, preferrably using jaxb annotations? I'm using jersey, but the answer doens't have to be specific to it. 回答1: How about the following? Using EclipseLink JAXB (MOXy) you could do the

Is it valid to specify xsi:type for an local complexType?

℡╲_俬逩灬. 提交于 2019-12-23 00:23:43
问题 We are having a problem with xsi:type since upgrading our server to jaxb 2. The xml client request in question was parsed ok when the server was running jaxb 1, but since upgrading to jaxb 2 we are seeing an error along the lines of: Error::cvc-elt.4.2: Cannot resolve 'er-request' to a type definition for element 'er-request' A client is specifying xsi:type as an attribute in a xml tag, but I don't think it's valid since the complex type in question has no such name. <?xml version="1.0"

JAXB2 type restriction not working?

陌路散爱 提交于 2019-12-22 10:34:20
问题 I have set up a test unit at github. Could someone please check why this is not working though the XML to unmarshal looks good? https://github.com/jjYBdx4IL/misc-tests/blob/master/src/test/java/jjybdx4il/jaxb/bugs/Stackoverflow26618647Test.java "<?xml version=\"1.0\" encoding=\"UTF-8\"?><message:GenericData xmlns:message=\"http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message\" xmlns:common=\"http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common\" xmlns:xsi=\"http://www.w3.org/2001

Generate java classes from a wsdl url with basic authentication

爱⌒轻易说出口 提交于 2019-12-22 08:08:44
问题 I am trying to generate the java classes from a WSLD file, that uses basic authentication. Although there are many plugins out there, I have to use the following one: org.jvnet.jaxb2.maven2:maven-jaxb2-plugin With wsimport or wsdl2java i have found the way to configure the basic authentication parameters. Using the maven-jaxb2-plugin i had no luck. My configuration follows: <plugin> <groupId>org.jvnet.jaxb2.maven2</groupId> <artifactId>maven-jaxb2-plugin</artifactId> <version>0.13.2</version>

Exception : “Missing class indicator field from database row [UnmarshalRecordImpl()].” when unmarshalling XML using EclipseLink JAXB (MOXy)

99封情书 提交于 2019-12-21 06:04:48
问题 Is it any way to unmarshalling with @XmlDescriminatorNode/@XmlDescrimintatorValue annotations next XML, or any workaround: <assets> <asset type="full"> <data_file role="source"> <locale name="ru-RU"/> </data_file> <data_file role="extension"> <locale name="ru-RU"/> </data_file> <data_file> <locale name="ru-RU"/> </data_file> </asset> </assets> My mapping classes: @XmlRootElement(name="data_file") @XmlAccessorType(XmlAccessType.FIELD) @XmlDiscriminatorNode("@role") public abstract class

How do you invoke schemagen in Java 11?

我的未来我决定 提交于 2019-12-21 05:15:15
问题 According to Oracle documentation the schemagen tool is removed from the JDK as part of JEP 320 (http://openjdk.java.net/jeps/320). That JEP points to Maven artifacts that now supply the missing tools. The coordinates of the artifacts are wrong in the JEP, updated coordinates are found in an answer to this question: Which artifacts should I use for JAXB RI in my Maven project? What is missing however is how to invoke the tools. There are shell scripts pointed to in the JEP that are in the

Specify a package instead of “classesToBeBound” for spring Jaxb2Marshaller

醉酒当歌 提交于 2019-12-21 03:38:13
问题 I am trying to use Jaxb2Marshaller to marshal a set of java classes using spring. I know this can be done using the following code <bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> <property name="classesToBeBound"> <list> <value>com.example.test1</value> <value>com.example.test2</value> </list> </property> </bean> What I would like to do is instead of specifying a list of classes, I would like to specify just the package name containing all the classes ( in the

jaxb when xsi:nil=true if any child element exists it is still showing

前提是你 提交于 2019-12-20 06:11:04
问题 I have the below xml output, how can we hide the child element (endDate) when parent element has attribute xsi:nil=true even child element is nillable=true? //XML Output <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <snapshots xmlns:xsi="w3.org/2001/XMLSchema-instance"; xmlns:ns3="ws.mycompany.com"; mask="PAC"> <Offers> <Offer xsi:type="wsMarketingOfferOP" entityId="1234" xsi:nil="true"> <endDate xsi:nil="true"/> </Offer> </Offers> </snapshots> // Snapshots class @XmlAccessorType