I have 2 sets of XSD's, one that generates RPC based calls, and another that defines the product specific methods. The RpcType object (generated by JAXB2) has a 'setRpcOperation' method defined by:
RpcType.setRpcOperation(JAXBElement<? extends RpcOperationType>)
That 'RpcOperation' object should be the 'specific product method' described above. One example is (also generated by JAXB2):
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "get-user-stats", propOrder = {
"reset"
})
public class GetUserStats {
protected Boolean reset;
/**
* Gets the value of the reset property.
*
* #return
* possible object is
* {#link Boolean }
*
*/
public Boolean isReset() {
return reset;
}
/**
* Sets the value of the reset property.
*
* #param value
* allowed object is
* {#link Boolean }
*
*/
public void setReset(Boolean value) {
this.reset = value;
}
}
Now, is it possible to create an instance of 'GetUserStatus' and add it to the RpcType object via setRpcOperation?
This type of scenario is common:
One schema to represent the message
Multiple schemas to represent the payload.
Below is one way this could be done:
Message Schema - message.xsd
Have one XML schema to represent your message envelope. Introduce one type to represent the body of the message. This type will be extended by the different payloads.
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/message"
xmlns="http://www.example.org/message"
elementFormDefault="qualified">
<xsd:element name="message">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="body" type="body"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="body">
</xsd:complexType>
</xsd:schema>
Payload Schema - customer.xsd
This schema corresponds to a specific type of message payload. Notice how the customer type extends the body type from the message schema.
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
targetNamespace="http://www.example.org/customer"
xmlns="http://www.example.org/customer"
xmlns:m="http://www.example.org/message"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xsd:import schemaLocation="message.xsd" namespace="http://www.example.org/message"/>
<xsd:complexType name="customer">
<xsd:complexContent>
<xsd:extension base="m:body">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
org.example.message.package-info
This class was generated from message.xsd.
#javax.xml.bind.annotation.XmlSchema(namespace = "http://www.example.org/message", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package org.example.message;
org.example.message.Message
This class was generated from message.xsd.
package org.example.message;
import javax.xml.bind.annotation.*;
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"body"
})
#XmlRootElement(name = "message")
public class Message {
#XmlElement(required = true)
protected Body body;
public Body getBody() {
return body;
}
public void setBody(Body value) {
this.body = value;
}
}
org.example.message.Body
This class was generated from message.xsd.
package org.example.message;
import javax.xml.bind.annotation.*;
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "body")
public class Body {
}
org.example.customer.package-info
This class was generated from customer.xsd.
#javax.xml.bind.annotation.XmlSchema(namespace = "http://www.example.org/customer", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package org.example.customer;
org.example.customer.Customer
This class was generated from customer.xsd.
package org.example.customer;
import javax.xml.bind.annotation.*;
import org.example.message.Body;
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "customer", propOrder = {
"name"
})
public class Customer extends Body {
#XmlElement(required = true)
protected String name;
public String getName() {
return name;
}
public void setName(String value) {
this.name = value;
}
}
Demo Class
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import org.example.customer.*;
import org.example.message.*;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Message.class, Customer.class);
Message message = new Message();
Customer customer = new Customer();
customer.setName("Jane Doe");
message.setBody(customer);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(message, System.out);
}
}
Output
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<message xmlns="http://www.example.org/message" xmlns:ns2="http://www.example.org/customer">
<body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:customer">
<ns2:name>Jane Doe</ns2:name>
</body>
</message>
EDIT #1
In response to your second question (Cast JAXB2 generated object to JAXBElement?)
I don't see where the JAXBElement comes into play with this example. I am able to run the following code:
import generated.GetFailedLoginCount;
import ietf.params.xml.ns.netconf.base._1.RpcType;
public class Demo {
public static void main(String[] args) {
RpcType rpc = new RpcType();
rpc.setMessageId("123");
GetFailedLoginCount rpcOperation = new GetFailedLoginCount();
rpc.setRpcOperation(rpcOperation);
}
}
EDIT #2
After changing the import to import to http://www.iana.org/assignments/xml-registry/schema/netconf.xsd I'm seeing the same behaviour as you.
To set the property correctly you will need to do something like:
RpcType rpc = new RpcType();
GetFailedLoginCount rpcOperation = new GetFailedLoginCount();
rpcOperation.setReset(true);
JAXBElement<GetFailedLoginCount> rpcOperationJE = new JAXBElement(new QName("foo"), GetFailedLoginCount.class, rpcOperation);
rpc.setRpcOperation(rpcOperationJE);
JAXBElement supplies the element name for the GetFailedLoginCount value. This is required because the element corresponding to the rpcOperation property is substitutable:
<xs:element name="get-config" type="getConfigType" substitutionGroup="rpcOperation" />
In your schema that imports netconf.xsd you should have an element of type "get-failed-login-count" that can be substituted for "rpcOperation". This will be supplied as a QName to the JAXBElement. Since we used element name "foo" above the schema update would look like:
<xs:element name="foo" type="get-failed-login-count" substitutionGroup="rpcOperation" />
Ok, so here is a subset of what I am trying to do. The above example was extremely helpful, but I still am not able to create a JAXBElement:
Base envelope can be found: http://www.iana.org/assignments/xml-registry/schema/netconf.xsd
Payload for rpcOperationType (I added the ** lines):
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:dmi="http://xml.juniper.net/dmi"
** xmlns:netconf="urn:ietf:params:xml:ns:netconf:base:1.0"
>
**<xs:import schemaLocation="netconf.xsd" namespace="urn:ietf:params:xml:ns:netconf:base:1.0"/>
<!-- get-failed-login-count -->
<xs:complexType name="get-failed-login-count">
**<xs:complexContent>
** <xs:extension base="netconf:rpcOperationType">
<xs:annotation>
<xs:appinfo>
<dmi:rpc-info>
<name>Get failed login count for Authentication failure and Exceeded user</name>
<description>
This command returns the Number of Logins refused due to exceeding allowed limits and Auth failure (24 hour moving window)
</description>
<rpc-reply-tag>failed-login-count</rpc-reply-tag>
</dmi:rpc-info>
</xs:appinfo>
</xs:annotation>
<xs:sequence>
<xs:element name="reset" type="xs:boolean" minOccurs="0">
<xs:annotation>
<xs:appinfo>
<dmi:param-info>
<name>Reset Stats</name>
<description>
This will govern the reseting of this statistics data. By default, the data is not reset.
</description>
</dmi:param-info>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
** </xs:extension>
**</xs:complexContent>
</xs:complexType>
Now, the generated GetFailedLogin class extends RpcOperationType, but I am not sure how to set it in the RpcType object:
RpcType rpc = new RpcType();
rpc.setMessageId("123");
GetFailedLoginCount rpcOperation = new GetFailedLoginCount();
rpc.setRpcOperation(); // Expects JAXBElement<? Extends RpcOperationType>
Related
I am trying to import this WSDL: https://gateway.monster.com:8443/bgwBroker
Among others, it includes this XSD: http://schemas.monster.com/current/xsd/Query.xsd, which contains this snippet:
<xsd:element name="Query">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Target" type="xsd:string"/>
<xsd:element name="SubTarget" type="xsd:string" minOccurs="0"/>
<xsd:element name="ResumeRestriction" minOccurs="0"/>
<xsd:element name="ReturnRestriction" minOccurs="0" maxOccurs="unbounded">
...
</xsd:element>
<xsd:element name="SelectBy" minOccurs="0" maxOccurs="unbounded">
...
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
...
<xsd:element name="ResumeRestriction">
...
</xsd:element>
As you can see, complex type ResumeRestriction and its fields is defined at the bottom, but referenced inside Query. There is a reference missing here. ReturnRestriction and SelectBy are defined inline and are generated correctly.
Using WSDL2Java, this generates the following annotated classes:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"target",
"subTarget",
"resumeRestriction",
"returnRestriction",
"selectBy"
})
#XmlRootElement(name = "Query")
public class Query {
#XmlElement(name = "Target", required = true)
protected String target;
#XmlElement(name = "SubTarget")
protected String subTarget;
#XmlElement(name = "ResumeRestriction")
protected Object resumeRestriction;
...
public void setResumeRestriction(Object value) {
this.resumeRestriction = value;
}
}
Making resumeRestriction of type Object instead of the right type.
If do have a generated version of ResumeRestriction just fine. They are just not being tied together:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"storeRenderedTextResume",
"doNotRenderSid",
"activeOnBoard"
})
#XmlRootElement(name = "ResumeRestriction")
public class ResumeRestriction {
...
}
If I now create a request using Spring Web Services, I cannot use the ResumeRestriction class, which I need in my request to set a specific flag.
ObjectFactory objectFactory = new ObjectFactory();
Query query = objectFactory.createQuery();
query.setTarget("JobSeekers");
ResumeRestriction resumeRestriction = objectFactory.createResumeRestriction();
resumeRestriction.setStoreRenderedTextResume(true);
query.setResumeRestriction(resumeRestriction);
getWebServiceTemplate().marshalSendAndReceive("https://gateway.monster.com:8443/bgwBroker", query);
This will throw the following error:
[com.sun.istack.SAXException2: Instance of "com.monster.schemas.monster.ResumeRestriction" is substituting "java.lang.Object", but "com.monster.schemas.monster.ResumeRestriction" is bound to an anonymous type.]
How can I solve this problem?
I obviously cannot change the WSDL or XSD, as I pull those in remotely. Is this is a bug on their side and if so, can I work around it?
You could specify the class reference in JAXB bindings file:
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
version="2.1"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jxb:extensionBindingPrefixes="xjc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation="http://java.sun.com/xml/ns/jaxb
http://java.sun.com/xml/ns/jaxb"
>
<jxb:bindings >
<jxb:globalBindings typesafeEnumMaxMembers="3000"/>
</jxb:bindings>
<jxb:bindings schemaLocation="http://schemas.monster.com/current/xsd/Query.xsd">
<jxb:bindings node="//xs:element[#name='Query']//xs:element[#name='ResumeRestriction']">
<jxb:class ref="com.monster.schemas.monster.ResumeRestriction"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
I ran SvcUtil.exe against XSD file to generate class. Then tried to create Object out of XML using following line. I get error shown below. Please see the detailed code below.
PersonType prs = (PersonType)xs.ReadObject(new MemoryStream(File.ReadAllBytes(sFileName)));
Error in line 3 position 58. Expecting element 'PersonType' from namespace 'http://service.a1.com/base1/2005/'.. Encountered 'Element' with name 'Person', namespace 'http://service.a1.com/base1/2005/'.
Command Used
svcutil.exe" "C:\Temp\S1\UseXSDExe\UseXSDExe\Sample2\Prs.xsd" /t:code /language:cs /out:C:\SPrxy.cs /dconly
Full code
(class generated by SvcUtils.exe)
[assembly: System.Runtime.Serialization.ContractNamespaceAttribute("http://service.a1.com/base1/2005/", ClrNamespace="service.a1.com.base1._2005")]
namespace service.a1.com.base1._2005
{
using System.Runtime.Serialization;
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="PersonType", Namespace="http://service.a1.com/base1/2005/")]
public partial class PersonType : object, System.Runtime.Serialization.IExtensibleDataObject
{
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
private string LastNameField;
private string FirstNameField;
public System.Runtime.Serialization.ExtensionDataObject ExtensionData
{
get
{
return this.extensionDataField;
}
set
{
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true, EmitDefaultValue=false)]
public string LastName
{
get
{
return this.LastNameField;
}
set
{
this.LastNameField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false, Order=1)]
public string FirstName
{
get
{
return this.FirstNameField;
}
set
{
this.FirstNameField = value;
}
}
}
}
(code used for converting XML to object)
public static void convertToObject(string sFileName)
{
DataContractSerializer xs = new DataContractSerializer(typeof(PersonType));
PersonType Person = (PersonType)xs.ReadObject(new MemoryStream(File.ReadAllBytes(sFileName)));
}
(XSD)
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://service.a1.com/base1/2005/" xmlns:bse1="http://service.a1.com/base1/2005/" elementFormDefault="qualified">
<xs:complexType name="PersonType">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="LastName" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="FirstName" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:element name="Person" type="bse1:PersonType"/>
</xs:schema>
(XML)
<?xml version="1.0" encoding="utf-8"?>
<pr:Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://service.a1.com/base1/2005/ Prs.xsd"
xmlns:pr="http://service.a1.com/base1/2005/">
<pr:LastName> Lane </pr:LastName>
<pr:FirstName> Fane </pr:FirstName>
</pr:Person>
I ran XSD.exe on same XSD file. Then I was able to convert XML to Object using XmlSerializer.Deserialize().
XSD does not have any attribute. I have validated XML against XSD.
Please let me know why Deserialize() fails.
Your XSD specifies a root element name and data type name that are different:
<xs:element name="Person" type="bse1:PersonType"/>
When svcutil.exe generates data contract classes for this type, it puts the type name into the data contract rather than the root element name. This appears to be intentional, see Svcutil generates wrong Name property value in DataContractAttribute. Perhaps it does this since the contract type itself could be re-used anywhere in the object graph, and there's no data contract equivalent of XmlRoot that applies only when the type in question is the document's root element.
As a workaround, you have a couple options:
Hardcode the expected root element name when constructing the serializer:
var xs = new DataContractSerializer(typeof(service.a1.com.base1._2005.PersonType), "Person", "http://service.a1.com/base1/2005/");
Preload the XML into an XDocument and use the actual root element name when constructing the serializer:
var doc = XDocument.Load(sFileName);
service.a1.com.base1._2005.PersonType person;
var xs = new DataContractSerializer(typeof(service.a1.com.base1._2005.PersonType), doc.Root.Name.LocalName, "http://service.a1.com/base1/2005/");
using (var reader = doc.CreateReader())
{
person = (service.a1.com.base1._2005.PersonType)xs.ReadObject(reader);
}
Or use XmlSerializer.
Here is the part of schema that I am using:
<xsd:complexType name="ContentType" mixed="true">
<xsd:annotation>
<xsd:documentation><![CDATA[
The content type is a broad base type allowing any content.
]]></xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="BaseContentType">
<xsd:sequence>
<xsd:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax"
/>
</xsd:sequence>
<xsd:attribute name="orientation" type="OrientationEnum" use="optional"
default="portrait">
<xsd:annotation>
<xsd:documentation><![CDATA[
The #orientation attribute is used to specify a "landscape"
orientation for the published form. This is primarily used
for schedules or for tables.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
And the binding file:
<jxb:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
version="2.1">
<jxb:bindings schemaLocation="../xsd/USLM-1.0.xsd">
<jxb:bindings
node="//xsd:group[#name='NoteStructure']">
<jxb:property name="NoteStructure3" />
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
And the xjc command to convert the schema to java objects:
xjc -d out -p test -b binding.xml schema.xsd
But the class generated for ContentType doesn't have class member for any. The generated class is below:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "ContentType")
#XmlSeeAlso({
HeadingType.class,
NoteType.class,
QuotedContentType.class,
ColumnType.class,
PType.class
})
public class ContentType
extends BaseContentType
{
#XmlAttribute(name = "orientation")
protected OrientationEnum orientation;
/**
* Gets the value of the orientation property.
*
* #return
* possible object is
* {#link OrientationEnum }
*
*/
public OrientationEnum getOrientation() {
if (orientation == null) {
return OrientationEnum.PORTRAIT;
} else {
return orientation;
}
}
/**
* Sets the value of the orientation property.
*
* #param value
* allowed object is
* {#link OrientationEnum }
*
*/
public void setOrientation(OrientationEnum value) {
this.orientation = value;
}
}
What am I doing wrong?
I have created a Web Service in Java with JAX-WS. It is a simple one that just returns an uppercased version of a String:
#WebService(endpointInterface = "mod2.Mod2")
public class Mod2Impl implements Mod2 {
#Override
public String mod2(String x) {
return x.toUpperCase();
}
}
and its interface:
#WebService
public interface Mod2 {
#WebMethod
String mod2(String x);
}
JAX generates the mod2.jaxws package for me with the relevant classes. The response is like this:
#XmlRootElement(name = "mod2Response", namespace = "http://mod2/")
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "mod2Response", namespace = "http://mod2/")
public class Mod2Response {
#XmlElement(name = "return", namespace = "")
private String _return;
/**
*
* #return
* returns String
*/
public String getReturn() {
return this._return;
}
/**
*
* #param _return
* the value for the _return property
*/
public void setReturn(String _return) {
this._return = _return;
}
}
When deployed it generates the proper WSDL file with an import to an XSD. This is the XSD:
<xs:schema xmlns:tns="http://mod2/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://mod2/">
<xs:element name="mod2" type="tns:mod2"/>
<xs:element name="mod2Response" type="tns:mod2Response"/>
<xs:complexType name="mod2">
<xs:sequence>
<xs:element name="arg0" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="mod2Response">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Now, what I want is to change the element named "return" in the XSD for whatever I want. I have tried changing the #XmlElement(name = "return", namespace = "") in the Mod2Response class but this throws the following error:
GRAVE: WSSERVLET11: failed to parse runtime descriptor: javax.xml.ws.WebServiceException: class mod2.jaxws.Mod2Response do not have a property of the name return
What is it I have to change to achieve this?
I have found the answer here.
I added #WebResult(name="mod2Result") to my interface:
#WebService
public interface Mod2 {
#WebMethod
#WebResult(name="mod2Result")
String mod2(String x);
}
and then run the wsgen again. Which generated the following Response:
#XmlRootElement(name = "mod2Response", namespace = "http://mod2/")
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "mod2Response", namespace = "http://mod2/")
public class Mod2Response {
#XmlElement(name = "mod2Result", namespace = "")
private String mod2Result;
/**
*
* #return
* returns String
*/
public String getMod2Result() {
return this.mod2Result;
}
/**
*
* #param mod2Result
* the value for the mod2Result property
*/
public void setMod2Result(String mod2Result) {
this.mod2Result = mod2Result;
}
}
which also has the #XmlElement(name = "mod2Result") as stated by Joshi but it also changed the name of variable, setter and getter. I tried with the #XmlElement straight in the Response class only with no success.
#WebService
public interface Mod2 {
#WebMethod
#XMLElement(name="returnChanged")
String mod2(String x);
}
You can try this code in your web service. This is a pseudo code.
How to implement #XmlElement.required flag using #XmlPath annotation in EclipseLink MOXy 2.4.1 version?
You can use the #XmlElement(required=true) along with the #XmlPath annotation to specify that the leaf element is required.
Customer
Below is a sample domain model with two fields mapped with #XmlPath on one of them I've also used #XmlElement(required=true).
package forum13854920;
import javax.xml.bind.annotation.*;
import org.eclipse.persistence.oxm.annotations.XmlPath;
#XmlAccessorType(XmlAccessType.FIELD)
public class Customer {
#XmlPath("personal-info/first-name/text()")
private String firstName;
#XmlPath("personal-info/last-name/text()")
#XmlElement(required=true)
private String lastName;
}
jaxb.properties
To use MOXy as your JAXB provider you need to include a file called jaxb.properties in the same package as your domain model with the following entry:
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
XML Schema
Below is the XML schema that corresponds to the domain model. Note how the last-name element does not have minOccurs="0".
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="customer">
<xsd:sequence>
<xsd:element name="personal-info" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="first-name" type="xsd:string" minOccurs="0"/>
<xsd:element name="last-name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Demo
The following demo code can be used to generate the XML schema.
package forum13854920;
import java.io.IOException;
import javax.xml.bind.*;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Customer.class);
jc.generateSchema(new SchemaOutputResolver() {
#Override
public Result createOutput(String namespaceURI, String suggestedFileName) throws IOException {
StreamResult result = new StreamResult(System.out);
result.setSystemId(suggestedFileName);
return result;
}
});
}
}
Currently EclipseLink JAXB (MOXy) does not have the equivalent of the required property on the #XmlElement annotation for the other segments of the path. If you are interested in this behaviour please enter an enhancement request using the link below:
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=EclipseLink