Cannot serialize Error in Android using ksoap2

孤人 提交于 2020-01-04 14:16:37

问题


I have a magento soap v2 api webservice. I can communicate with this from android using ksoap2.The xml and coding I tried is given below.

------------XML Api-----------

<operation name="catalogProductCreate">
<documentation>Create new product and return product id</documentation>
<input message="typens:catalogProductCreateRequest"/>
<output message="typens:catalogProductCreateResponse"/></operation>


<message name="catalogProductCreateRequest">
<part name="sessionId" type="xsd:string"/>
<part name="type" type="xsd:string"/>
<part name="set" type="xsd:string"/>
<part name="sku" type="xsd:string"/>
<part name="productData" type="typens:catalogProductCreateEntity"/>
<part name="storeView" type="xsd:string"/>
</message>


<complexType name="catalogProductCreateEntity">
<all>
<element name="categories" type="typens:ArrayOfString" minOccurs="0"/>
<element name="websites" type="typens:ArrayOfString" minOccurs="0"/>
<element name="file" type="typens:catalogProductImageFileEntity" minOccurs="0"/
<element name="name" type="xsd:string" minOccurs="0"/>
<element name="description" type="xsd:string" minOccurs="0"/>
<element name="short_description" type="xsd:string" minOccurs="0"/>
<element name="weight" type="xsd:string" minOccurs="0"/>
<element name="status" type="xsd:string" minOccurs="0"/>
</all>
</complexType>

<complexType name="catalogProductImageFileEntity">
<all>
<element name="content" type="xsd:string"/>
<element name="mime" type="xsd:string"/>
<element name="name" type="xsd:string" minOccurs="0"/>
</all>
</complexType>

------------MainClass---------

request = new SoapObject(NAMESPACE,"catalogProductCreate");

        request.addProperty("sessionId", sessionId);

        request.addProperty("type", "simple");
        request.addProperty("set", "4");
        request.addProperty("sku", sku.toString());

        //-----use Kvm Serializable class to serialize the key value data-------

        CreateProductKVMserialize createproductkvm = new CreateProductKVMserialize();

        createproductkvm.Name = name;
        createproductkvm.Description = description;
        createproductkvm.ShortDescription = shortdescription;

        createproductkvm.Weight = weight;
        createproductkvm.Status = "1";
        createproductkvm.Price = price;

        PropertyInfo pi = new PropertyInfo();
        pi.setName("productData");
        pi.setValue(createproductkvm);
        pi.setType(createproductkvm.getClass());
        request.addProperty(pi);

        env.setOutputSoapObject(request);

        env.addMapping(NAMESPACE, "productData",new CreateProductKVMserialize().getClass());

        androidHttpTransport.call("", env);
        Object product_create = env.getResponse();
        Log.d("mainactivity "," "+product_create.toString());

-------------CreateProductKVMserialize class----------

public class CreateProductKVMserialize implements KvmSerializable{

public String[] Categories; // this array i cant send it shows cannot serialize error
public String Name;
public String Description;
public String ShortDescription;
public String Weight;
public String Status;
public String Price;

public CreateProductKVMserialize(){}

public CreateProductKVMserialize(String[] categories,String name, String description, String shortdescription, String weight,String status,String price) {

    Categories = categories;
    Name = name;
    Description = description;
    ShortDescription = shortdescription;
    Weight = weight;
    Status= status;
    Price = price;
}

@Override
public Object getProperty(int arg0) {
    // TODO Auto-generated method stub
     switch(arg0)
        {
        case 0:
            return Categories;
        case 1:
            return Name;
        case 2:
            return Description;
        case 3:
            return ShortDescription;
        case 4:
            return Weight;  
        case 5:
            return Status;  
        case 6:
            return  Price ; 

        }

        return null;

}

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

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

     switch(index)
        {
        case 0:
            info.type = PropertyInfo.VECTOR_CLASS;
            info.name = "categories";
            break;
        case 1:
            info.type = PropertyInfo.STRING_CLASS;
            info.name = "name";
            break;
        case 2:
            info.type = PropertyInfo.STRING_CLASS;
            info.name = "description";
            break;
        case 3:
             info.type = PropertyInfo.STRING_CLASS;
             info.name = "short_description";
            break;
        case 4:
             info.type = PropertyInfo.STRING_CLASS;
             info.name = "weight";
            break;
        case 5:
             info.type = PropertyInfo.STRING_CLASS;
             info.name = "status";
            break;
        case 6:
             info.type = PropertyInfo.STRING_CLASS;
             info.name = "price";
            break;

        default:break;
        }
}

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

    switch(index)
    {
    case 0:
        Categories = (String[])value;
        break;
    case 1:
        Name = value.toString();
        break;
    case 2:
        Description = value.toString();
        break;
    case 3:
        ShortDescription = value.toString();
        break;
    case 4:
        Weight = value.toString();
        break;
    case 5:
        Status = value.toString();
        break;
    case 6:
        Price = value.toString();
        break;

    default:
        break;
    }
 }

}

But the problem is I can't send the data in complex type(eg:Array) and till "catalogProductCreateEntity" only I can communicate, if I send array data it shows error "Cannot serialize..". How to send data in the form "typens:ArrayOfString", and how to communicate with "catalogProductImageFileEntity"(type of a name in "catalogProductCreateEntity").

来源:https://stackoverflow.com/questions/24951805/cannot-serialize-error-in-android-using-ksoap2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!