开发者

Inheritance on method parameters not working

开发者 https://www.devze.com 2023-01-16 12:48 出处:网络
I have a test web service with following methods & classes, Method public String addPerson(P开发者_开发技巧erson p) {

I have a test web service with following methods & classes,

Method

public String addPerson(P开发者_开发技巧erson p) {
if(p instanceof Employee) {
return "Employee"; 
}
return "Person";
}

Note: Method is annotated with @WebMethod, @WebParam annotations, so is web service with @WebService.

Classes

Class Person {
public String name;
}

Class Employee extends Person{
public int employeeNo;
}

Observations

  1. In spite of client sending the serialized Employee object the web service is always taking it as a Person object. I have checked the soap packet on client with firebug tool, employee number is present in the payload. I also check soap MESSAGE on server & their I dont see employee number attribute.

Question

  1. Is this an expected behavior? I hope it is not.
  2. Is there any way I can make this work without having write custom SOAP decoders?


I think this is how it should be. Because when the data is sent the inheritance information is lost and it will only decode the data back to the type declared in the webservice method in your case to the Person object.


After digging deep, we found out that the issue was with the client side which generated SOAP packet which doesn't work in such scenario. Client is expected to put name(s) of type of derived object(s) (Employee) in the element corresponding to the operation but the client we are using is not doing so because of which "javax.xml.bind.UnmarshalException: Unable to create an instance of ..." is reported.

0

精彩评论

暂无评论...
验证码 换一张
取 消