You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@wink.apache.org by Matthew Graham <mj...@cacr.caltech.edu> on 2011/02/16 23:49:36 UTC

Wink, JAXB and xsi:type

Hi,

I'm trying to use Wink with JAXB objects generated from a schema with inheritance. 

In the schema, I have NodeType which is the parent of DataNodeType which is the parent of ContainerNodeType and all of which are represented in XML as <node> with the appropriate value of xsi:type, e.g., <node xsi:type="DataNodeType">. I've generated JAXB objects from the schema with xjc.
Now in my service, I have a method which should take an XML node representation from a HTTP PUT:

    @Path("{nodeid}")
    @PUT
    @Consumes(MediaType.APPLICATION_XML)
    @Produces(MediaType.APPLICATION_XML)
    public JAXBElement<NodeType> putNode(@PathParam("nodeid") String nodeid, NodeType node) {
	System.out.println("Received node " + nodeid + " " + node.getClass());
	ObjectFactory factory = new ObjectFactory();
	return factory.createNode(node);
    }

However, when I PUT a <node xsi:type="DataNodeType"> to the service, an object of class NodeType is created instead of DataNodeType. If I change the method signature to:

public JAXBElement<NodeType> putNode(@PathParam("nodeid") String nodeid, DataNodeType node) 

then it unmarshalls fine but I don't want to write a different method for each specific different type of node. 
I've also tried a ContextResolver defining a specific JAXBContent for the package generated from the schema but this does not seem to do anything (even though it is correctly registered and called).

I can always get the raw HTTPServletRequest object and do the unmarshalling myself but that seems to defeat the purpose of using JAXB.

Any ideas?

	Cheers,

	Matthew