return type polymorphism issue, please help
beligum Dec 13, 2007 10:59 PMHi all, I guess this should be easy for some of you experts, so I hope to get an answer here, after searching for this bug for a couple of hours now.
Here's the situation:
@XmlJavaTypeAdapter(AbstractInodeImpl.Adapter.class) public interface Inode extends Serializable, Comparable<Inode>, Cloneable { //definition of getters,setters,... }
@Entity @Table(name="inode") @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn( name="type", discriminatorType=DiscriminatorType.STRING ) @XmlSeeAlso({FileInode.class, DirectoryInode.class}) public abstract class AbstractInodeImpl implements Inode { //implementation of getters,setters,... static public class Adapter extends XmlAdapter<AbstractInodeImpl, Inode> { public Inode unmarshal(AbstractInodeImpl v) { return v; } public AbstractInodeImpl marshal(Inode v) { return (AbstractInodeImpl)v; } } }
@Entity @Name("directoryInode") @DiscriminatorValue("directory") public class DirectoryInode extends AbstractInodeImpl implements Serializable { // more implementation }
@Entity @Name("fileInode") @DiscriminatorValue("file") public class FileInode extends AbstractInodeImpl implements Serializable { // even more... }
@Stateless @WebService(name = "FileSystemService", serviceName = "FileSystemService") @Name("fileSystemService") @WebContext(contextRoot="/tumbolia/services", urlPattern="/FileSystemService") public class FileSystemServiceImpl implements FileSystemService, Serializable { @WebMethod public List<Inode> getAllChildren(String inodePath) { List<Inode> children = ((FileSystemManager)Component.getInstance("fileSystemManager", true)).getInodePathChildren(inodePath); return children; } }
I generate my JAXB beans with wsconsume or wsimport (have tried both) from the wsdl that was automatically generated.
When I call the webservice in the last bean, I get this exception:
[javax.xml.bind.UnmarshalException: Unable to create an instance of com.acepostproduction.tumbolia.webservice.AbstractInodeImpl - with linked exception: [java.lang.InstantiationException]] com.acepostproduction.virtuolia.exceptions.WsException: [TumboliaFileSystemCommunicator] Error while calling getAllChildren(): javax.xml.bind.UnmarshalException - with linked exception: [javax.xml.bind.UnmarshalException: Unable to create an instance of com.acepostproduction.tumbolia.webservice.AbstractInodeImpl - with linked exception: [java.lang.InstantiationException]] at com.acepostproduction.virtuolia.communicator.TumboliaFileSystemCommunicator.getAllChildren(TumboliaFileSystemCommunicator.java:87) at com.acepostproduction.virtuolia.VirtuoliaDiskDriver.startSearch(VirtuoliaDiskDriver.java:340) ...
Any ideas why the polymorphism on the return value is failing?
It would be great if someone could give me a hint here.
bram