-1

I am having following Student class,

public class Student implements KvmSerializable {

    private String ID;
    private String Mark;
    private String Percentage;

    public String getID() {
        return FoodItemID;
    }

    public void setID(String ID) {
        ID = ID;
    }

    public String getMark() {
        return Modifier;
    }

    public void setMark(String mark) {
        Modifier = modifier;
    }

    public String getPercentage() {
        return Quantity;
    }

    public void setPercentage(String percentage) {
        Percentage = percentage;
    }

    @Override
    public Object getProperty(int arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int getPropertyCount() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
        // TODO Auto-generated method stub

    }

    @Override
    public void setProperty(int arg0, Object arg1) {
        // TODO Auto-generated method stub

    }

}

And Student list in following signature,

ArrayList<HashMap<String, String>> studentList;

Now I want to send this list to WCF service, So I have created following PropertyInfo Object,

for (int i = 0; i < studentList.size(); i++) {
    Student items = new Student();
    items.setID(studentList.get(i).get("ID"));
    items.setMark(studentList.get(i).get("Mark"));
    items.setPercentage(studentList.get(i).get("Percentage"));          
    li.add(items);
}
PropertyInfo pi = new PropertyInfo();
pi.setName("StudentList");
pi.setValue(li);
pi.setType(Student.class);

And my request is

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

request.addProperty("StudentList", pi);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
envelope.implicitTypes = true;
HttpTransportSE transport = new HttpTransportSE(URL);
try {
    transport.call(SOAP_ACTION, envelope);
} catch (final Exception e) {
    activity.runOnUiThread(new Runnable() {

        public void run() {
            new CustomToast(activity, SOAP_ACTION + " - "
                    + e.getMessage() + " error").show();
            e.printStackTrace();
        }
    });
}
try {
    fault = (SoapFault) envelope.bodyIn;
    activity.runOnUiThread(new Runnable() {

        public void run() {
            if (fault != null) {
                new CustomToast(activity, fault.getMessage())
                        .show();
            }
        }
    });
} catch (Exception e) {
    e.printStackTrace();
}
try {
    result = (SoapObject) envelope.bodyIn;
    System.out.println("result in getdata : " + result);
} catch (Exception e) {
    e.printStackTrace();
}

But this gives me following exception,

java.lang.RuntimeException: Cannot serialize: StudentList : [com.example.citrusz.Student@410c08f8]
halfer
  • 19,824
  • 17
  • 99
  • 186
Gunaseelan
  • 14,415
  • 11
  • 80
  • 128

1 Answers1

0

don't pass the PropertyInfo to the addProperty function.
Instead of

request.addProperty("StudentList", pi);

add it directly

request.addProperty("StudentList", li);
Sam
  • 759
  • 1
  • 4
  • 10