I'm trying to marshall an concrecte class from a jersey 2 service+ jaxb RI implmentation based on this xsd:
<xs:schema xmlns="http://namespace"
targetNamespace="http://namespace"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
elementFormDefault="qualified"
jaxb:version="2.0"
version="1.0">
<xs:element name="Expression" type="ATExpression" />
<xs:element name="Expressions" type="ATExpressions" />
<xs:complexType name="ATExpressions">
<xs:sequence>
<xs:element type="ATExpression" name="Expression" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ATExpression" abstract="true"/>
<xs:complexType name="TExpressionWithRef">
<xs:complexContent>
<xs:extension base="ATExpression">
<xs:attribute name="ref" type="xs:string" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="TExpressionWithContent">
<xs:complexContent>
<xs:extension base="ATExpression">
<xs:sequence>
<xs:element name="gufid" type="xs:string"/>
<xs:element name="code" type="xs:string"/>
<xs:element name="expression" type="xs:string"/>
<xs:element name="expressionType" type="xs:string"/>
<xs:element name="description" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
I have added a XmlRootElement on the TExpressionWithContent and ask my jersey service to simply return a TExpressionWithContent:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "TExpressionWithContent", propOrder = {
"gufid",
"code",
"expression",
"expressionType",
"description"
})
@XmlRootElement(name = "Expression")
public class TExpressionWithContent
extends ATExpression
{
@XmlElement(required = true)
protected String gufid;
@XmlElement(required = true)
protected String code;
@XmlElement(required = true)
protected String expression;
@XmlElement(required = true)
protected String expressionType;
protected String description;
/**
* Obtient la valeur de la propriété gufid.
*
* @return
* possible object is
* {@link String }
*
*/
public String getGufid() {
return gufid;
}
/**
* Définit la valeur de la propriété gufid.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setGufid(String value) {
this.gufid = value;
}
/**
* Obtient la valeur de la propriété code.
*
* @return
* possible object is
* {@link String }
*
*/
public String getCode() {
return code;
}
/**
* Définit la valeur de la propriété code.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setCode(String value) {
this.code = value;
}
/**
* Obtient la valeur de la propriété expression.
*
* @return
* possible object is
* {@link String }
*
*/
public String getExpression() {
return expression;
}
/**
* Définit la valeur de la propriété expression.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setExpression(String value) {
this.expression = value;
}
/**
* Obtient la valeur de la propriété expressionType.
*
* @return
* possible object is
* {@link String }
*
*/
public String getExpressionType() {
return expressionType;
}
/**
* Définit la valeur de la propriété expressionType.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setExpressionType(String value) {
this.expressionType = value;
}
/**
* Obtient la valeur de la propriété description.
*
* @return
* possible object is
* {@link String }
*
*/
public String getDescription() {
return description;
}
/**
* Définit la valeur de la propriété description.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setDescription(String value) {
this.description = value;
}
}
However, by doing this my xml is missing the xsi:type="TExpressionWithContent" on the Expression root element:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Expression xmlns="http://namespace">
<gufid>327EDAB5-8B95-41B4-B583-5B58914BED59</gufid>
<code>Gendddre5448</code>
<expression>Particulier42.genre = lookup('genre', Particulier.genre) </expression>
<expressionType>TRANSFORMATION</expressionType>
<description>descriptSDFDFDFDion2</description>
</Expression>
I cannot remove the XmlRootElement cause jersey won't find any MessageBodyWriter for my class and so won't map the TExpresionWithContent with jaxb. Any help would be appreciated
Found my error. I had to wrap the concrete class into the abstract class.