Following are the classes I am using for create sub classes using MOXy JAXB conversion on WebLogic 10.3.2 version. I am using the EclipseLink 2.4.1 MOXy for generating the XML. I am unable to generate the type attribute in the following code. Let me know if I am doing anything wrong here.
I am using EclipseLink MOXy 2.4.1 and WebLogic 10.3.2 and MOXy 2.4.1 is configured in the WebLogic
import javax.xml.bind.annotation.*;
import org.eclipse.persistence.oxm.annotations.XmlDiscriminatorNode;
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlDiscriminatorNode("@type")
public abstract class BaseEntity {
private String firstName;
private String lastName;
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
}
Subclass
package forum13831189;
import org.eclipse.persistence.oxm.annotations.XmlDiscriminatorValue;
@XmlDiscriminatorValue("xyz")
public class XyzEntity extends BaseEntity {
public XyzEntity() {
super();
}
}
Another Sub Class
import org.eclipse.persistence.oxm.annotations.XmlDiscriminatorValue;
@XmlDiscriminatorValue("Abc")
public class AbcEntity extends BaseEntity {
}
RESTful Web Service Class:
@GET
@Path("/xyz")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Representation getAccount() throws CPAException {
Representation rep = new Representation();
BaseEntity entity = new XyzEntity();
entity.setFirstName("first-name");
entity.setLastName("last-name");
rep.setEntity(entity);
return rep;
}
@XmlRootElement
static class Representation {
private BaseEntity entity;
public BaseEntity getEntity() {
return entity;
}
public void setEntity(BaseEntity entity) {
this.entity = entity;
}
}
The above is generating the following XML.
<representation>
<firstName>first-name</firstName>
<lastName>last-name</lastName>
</representation>
The attribute type is not generated in the above.
Thanks a lot. Yes, I missed jaxb.properties in the above. Also, Yes when I use the PUT or POST, when XML is de-serialized, it is not able to create the subclasses if @XmlSeeAlso is not present.