cancel
Showing results for 
Search instead for 
Did you mean: 

Deserializing failed during calling webservice

former_member182374
Active Contributor
0 Kudos

Hi all,

I've an EJB which exposes some business methods as Web Service.

One parameter of a business method is an array of an interface called IPair (which is actually an interface that a class called Pair implements) - see code:


public int createRequest3( // Business method
	String userID,
	int formID,
	IPair[] pairs,
	String comment,
	int linkedRequestID,
	String theYear) {
	// TODO : Implement
	return 999;
}

public interface IPair {
	public String getKey();
	public String getValue();
	public void setKey(String string);
	public void setValue(String string);
}

public class Pair implements IPair, Serializable {
	private String key;
	private String value;
	
	public String getKey() {
		return key;
	}

	public String getValue() {
		return value;
	}

	public void setKey(String string) {
		key = string;
	}

	public void setValue(String string) {
		value = string;
	}
}

When I test it by using WSNavigator I can choose between IPair & Pair and if I select Pair the method works.

WSNavigator screen shot: http://img7.imageshack.us/i/pairp.jpg/

When I import it to Web Dynpro only the IPair interface is imported and since I cannot create an instance of Pair I get an exception:

Caused by: java.lang.reflect.InvocationTargetException: Deserializing fails. Nested message: XML Deserialization Error. Can not create instance of class [w.x.y.x.interfaces.IPair] when deserializing XML type [urn:w.x.y.x.interfaces][IPair]..

If I use the deprecated Web Service model everything works because both IPair and Pair are generated in the WD side (it seems that WSNavigator works like the deprecated Web Service Model in WD).

How can I use this kind of complex type when using the Adaptive Web Service Model?

Regards,

Omri

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

The interface IPair should extend Serializable or Externalizable too.

Regards,

Satyajit

former_member182374
Active Contributor
0 Kudos

Hi Satyajit Chakraborty,

Thanks for your help.

I'm extending now IPair:

public interface IPair extends Serializable {
	public String getKey();
	public String getValue();
	public void setKey(String string);
	public void setValue(String string);
}

The problem remains.

In pic1 you can see what happens when using class (the way it should be):

http://img16.imageshack.us/i/classfw.jpg/

In pic2 you can see what happens when using interface (this is what WD does - in WD I can't choose between the class or the interface, only 'IPair' is created by the adaptive web service model) and this is the exact exception I'm getting when I run it from WD.

http://img24.imageshack.us/i/interfacexw.jpg/

Deprecated model still works...

Regards,

Omri

Former Member
0 Kudos

Hi,

Are you using JavaEE 5 or above? If yes then you should try using the @XmlJavaTypeAdapter annotation. You can find more details [here|https://jaxb.dev.java.net/guide/Mapping_interfaces.html].

If not then try using an abstract class instead of an interface like so:


public abstract class AbstractPair implements Serializable {
	public String getKey();
	public String getValue();
	public void setKey(String string);
	public void setValue(String string);
}

Regards,

Satyajit

former_member182374
Active Contributor
0 Kudos

HI,

I've managed to solve it by converting simple Java project (not EJB) to Web Service.

Same classes and it works...

Thanks for your help,

Omri

Edited by: Omri Cohen on Oct 26, 2009 1:24 PM

Answers (0)