sendding名单成KvmSerializable类 [英] sendding List into a KvmSerializable class

查看:630
本文介绍了sendding名单成KvmSerializable类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何,我可以送的java.util.List的名单,在Ksoap2实现KvmSerializable android上的一类里面?运行应用程序时,我得到了以下错误:

how I can to send a List of java.util.List inside a class that implements KvmSerializable in Ksoap2 on android?. when running the application I get the following error:

了java.lang.RuntimeException:无法序列

java.lang.RuntimeException: Can not serialize

我的code是这样的:

my code is this:

SoapSerializationEnvelope env = new SoapSerializationEnvelope(SoapEnvelope.VER11);
env.dotNet = false;
env.xsd = SoapSerializationEnvelope.XSD;
env.enc = SoapSerializationEnvelope.ENC;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

Car car= new Car();
byte[] bytes = {1, 2, 3, 4, 5, 6, 7, 8, 9};
car.setBytes(bytes);
List<Door> list = new ArrayList<Door>();
car.setList(list);
PropertyInfo pi = new PropertyInfo();
pi.setName("car");
pi.setValue(car);
pi.setType(car.getClass());
request.addProperty(pi);
env.setOutputSoapObject(request);
env.addMapping(NAMESPACE, "Car", byte[].class, new MarshalBase64());

Car类:

public class Car implements KvmSerializable{

    private byte[] bytes;
    private List<Door> list;

    public void setBytes(byte[] bytes) {
        this.bytes= bytes;
    }

    public void setList(List<Door> list) {
        this.list= list;
    }

    @Override
    public Object getProperty(int arg0) {
        switch(arg0){
            case 0:
                return bytes;
            case 1:
                return list;

        }

         return null;
    }

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

    @Override
    public void getPropertyInfo(int ind, Hashtable ht, PropertyInfo info) {
        switch(ind){
                case 0:
                    info.type = MarshalBase64.BYTE_ARRAY_CLASS;
                    info.name = "bytes";
                    break;
                 case 1
                    info.type = List.class;
                    info.name = "list";
                    break;

                default:break;
        }

    }

    @Override
    public void setProperty(int ind, Object val) {
        switch(ind){
                case 0:
                    bytes = (byte[])val;
                    break;
                case 1:
                    list= (List<Door>)val;
                    break;

        }

    }

}

门类实现KvmSerializable,任何人都可以帮我吗?

the Door class implements KvmSerializable, anyone can help me?

感谢

推荐答案

有几种方法可以使类序列化在ksoap2:

There are several ways to make class serializable in ksoap2:


  1. 对于这个类来创建对象马歇尔和 addMapping

  2. 实现接口 KvmSerializable

  3. SoapObject 矢量默认序列化。

  1. Create marshall object for this class and addMapping for it
  2. Implement interface KvmSerializable
  3. SoapObject and Vector serializable by default.

列表不匹配任何这种情况,所以你得到一个错误。
您可以创建类的定制马歇尔对象列表或创造条件,落实列表接口和 KvmSerializable 。或者你可以使用矢量(或者甚至可能将您的对象SoapObject通过调用方法addProperty addSoapObject )。

List does not match any of this condition, so you get an error. You can create custom marshall object for class List or create custom class which would implement List interface and KvmSerializable. Or you can use Vector (or may be even convert your object to SoapObject by calling addProperty and addSoapObject).

这篇关于sendding名单成KvmSerializable类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆