title: Ksoap: Cannot Serialize exception when passing user defined class as parameter to web method
body: <p>I have spent several days trying to figure out how can I make my user defined java class serializable, so that i can send it as a parameter in android ksoap call to c# web method .
  Below is my code and the exceptions thrown in logcat when calling the webservice , I would be thankful if i get an immediate answer or help .</p>
  
  <p>My java class <code>XY.java</code>: </p>
  
  <pre><code>import org.ksoap2.serialization.KvmSerializable;
  import org.ksoap2.serialization.PropertyInfo;
  
  public class XY implements KvmSerializable {
      public static Class XY_CLASS = XY.class;
      private String MyNum;
      private String OppPhoneNum;
      private String Name;
  
      public XY()
      {
  
      }
      public XY(String MyNum, String Name, String oppNum)
      {
          this.MyNum = MyNum;
          this.Name = Name;
          this.OppPhoneNum = oppNum;
      }
  
      public String getPhoneNum() {
          return MyNum;
      }
      public void setPhoneNum(String MyNum) {
          this.MyNum = MyNum;
      }
      public String getName() {
          return Name;
      }
      public void setName(String Name) {
          this.Name = Name;
      }
      public String getOpponentPhoneNum() {
          return OppPhoneNum;
      }
      public void setOpponentPhoneNum(String OppPhoneNum) {
          this.OppPhoneNum = OppPhoneNum;
      }
      @Override
      public Object getProperty(int arg0) {
  
          switch(arg0)
          {
          case 0:
              return MyNum;
          case 1:
              return OppPhoneNum;
          case 2:
              return Name;
          }
  
          return null;
      }
      @Override
      public int getPropertyCount() {
          // TODO Auto-generated method stub
          return 3;
      }
      @Override
      public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
  
  
  
          switch(index)
          {
          case 0:
              info.type = PropertyInfo.STRING_CLASS;
              info.name = "MyNum";
              break;
          case 1:
              info.type = PropertyInfo.STRING_CLASS;
              info.name = "OppPhoneNum";
              break;
          case 2:
              info.type = PropertyInfo.STRING_CLASS;
              info.name = "Name";
              break;
          default:break;
          }
      }
      @Override
      public void setProperty(int index, Object value) {
  
  
          switch(index)
          {
          case 0:
              MyNum = value.toString();
              break;
          case 1:
              OppPhoneNum = value.toString();
              break;
          case 2:
              Name = value.toString();
              break;
          default:
              break;
          }
      }
  }
  </code></pre>
  
  <p>C# equivalent class: </p>
  
  <pre><code>[Serializable]
  public class XY
      {
  
          public System.String Name
          {
              get;
              set;
          }
          public System.String MyNum
          {
              get;
              set;
          }
          public System.String OppPhoneNum
          {
              get;
              set;
          }
      }
  </code></pre>
  
  <p>And this is how i am calling the service using ksoap from my activity:</p>
  
  <pre><code>private void unKnown(List&lt;XY&gt; entries) 
      {
  
           //Initialize soap request + add parameters
          SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
  
          PropertyInfo entriesProp =new PropertyInfo();
          entriesProp.setName("entries");          
          entriesProp.setValue(entries);
          entriesProp.setType(ArrayList.class);
  
  
          //Use this to add parameters
          request.addProperty(entriesProp);
          //Declare the version of the SOAP request
  
          SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
          envelope.setOutputSoapObject(request);
          envelope.addMapping(NAMESPACE, "XY", XY.XY_CLASS);
  
          envelope.dotNet = true;
  
          try {
  
                HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
  
                //this is the actual part that will call the webservice
  
                androidHttpTransport.call(SOAP_ADDCONTACTS, envelope);
  
                // Get the SoapResult from the envelope body.
  
                if (envelope.bodyIn instanceof SoapFault) 
                {
                    String str= ((SoapFault) envelope.bodyIn).faultstring;
                    Log.i("", str);
                } 
                else 
                {
                    SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
                    if(resultsRequestSOAP != null)
                    {
                        Log.i("AddContacts", "Adding Contacts succeeded");
                    }
                }
          }
          catch (Exception e)
          {
                e.printStackTrace();
          }
      }**
  </code></pre>
  
  <p>Logcat Exception :</p>
  
  <pre><code>java.lang.RuntimeException: Cannot Serialize: [XY .....** 
  </code></pre>
  
  <p>Note : i am trying to pass list of XY objects as parameter to the web service method .
  I would appreciate any help .</p>