I have the following situation:
There is a tree structure for logical expressions, which is used in our application and is determined by a hierarchy of four classes:
Node - abstract superclass
OrNode - a subclass of Node class representing OR
AndNode - a subclass of Node class representing AND
Leaf - a subclass of Node class representing Node sheet containing some data
Now the tree structure should be transferred to the web service, which will perform some operation on the tree (for example, evaluating the result, collecting some other information)
The signature of this WS-Operation might look like this:
public TheResult evaluateTree(Node tree);
We use JAX-WS and generate web service classes using wsimport. Firstly, there are no classes generated for OrNode, AndNode and Leaf. So, we added them manually. We will convert the classes used on the client side into the created classes created by wsimport. Then we want to call the web service operation with the transformed tree as a parameter. But there is an exception saying something like:
javax.xml.ws.soap.SOAPFaultException: javax.xml.bind.UnmarshalException - with linked exception: [javax.xml.bind.UnmarshalException: Unable to create an instance of InterfaceEntities.Node - with linked exception: [java.lang.InstantiationException]]
Here are the Wrapper classes that we added and generated classes:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "OrNode")
public class OrNode
extends Node
{
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AndNode")
public class AndNode
extends Node
{
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "leaf")
public class Leaf
extends Node
{
...
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "node", propOrder = {
"children",
"resultSet",
})
@XmlSeeAlso({
Leaf.class,
OrNode.class,
AndNode.class
})
public abstract class Node {
...
}
EDIT:
Here is the generated XML file when used Marshalleras described on the Blaise Doughan blog (see below):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:treeInfo xmlns:ns2="http://webservice.api.process/">
<tree xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:OrNode">
<children xsi:type="ns2:leaf">
</children>
<children xsi:type="ns2:leaf">
</children>
</tree>
</ns2:treeInfo>
This is a simple tree consisting of one orNode and two leaf nodes, treeInfo represents a class containing a Node / tree object with other information. It is marked as XmlRootElement with the corresponding annotation.
Did we miss something?
Thanks in advance!