axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ramaswamy, Muthu" <>
Subject Server throws ClassCastException when List member is referenced.
Date Sat, 16 Nov 2002 03:24:35 GMT
Hi All-

I am able to return an object that contains List, from a service. 
When I return the same object to the Server and then refer the objects in
the list, I get java.lang.ClassCastException.

The echoBean method takes the SimpleTestBean object as an argument. It then
prints the List members.

(1) Following is the RPC call issued by the Axis Client. 
<?xml version="1.0" encoding="UTF-8"?>
  <ns1:echoBean xmlns:ns1="SimpleTest">
    <name>Your Name</name>
    <phones SOAP-ENC:arrayType="xsd:any[3]">
      <phoneNum>123 456 7890</phoneNum>
      <phoneNum>789 012 3456</phoneNum>
      <phoneNum>345 012 3456</phoneNum>
    <place>Your Place</place>

(2) Here is the Code for SimpleTestBean.
public class SimpleTestBean {

  private String name;
  private String place;
  private List phones;

  public SimpleTestBean() {
     name = "Your Name";
     place = "Your Place";

  public void setName(String name)
  { = name;

  public String getName()

  public void setPlace(String place)
  { = place;

  public String getPlace()

  public List getPhones()
     return this.phones;

  public void setPhones(List phones)
     this.phones = phones;

(3) Here is the code for the echoBean method in the SimpleTest service
public void echoBean(SimpleTestBean stb)
     System.out.println("name is" + stb.getName());
     System.out.println("place is" + stb.getPlace());
     List myPhoneList = stb.getPhones();

     for (int i=0; i<myPhoneList.size(); i++)
        SimplePhoneBean spb = (SimplePhoneBean) myPhoneList.get(i);  //this
line throws the ClassCastException.
        System.out.println("Printing Phone List");
        System.out.println(spb.getPhoneType() + ":" + spb.getPhoneNum());


I get the ClassCastException when I try to refer the List member. 
When I tested the function from a Java client it works fine. Problem is
after de-serialization by Axis. 
The myPhoneList.size() returns three, which is correct as I send three
Problem is when I try to cast it to the SimplePhoneBean object, I get the

Appreciate your input to solve my problem.



View raw message