sendding名单成KvmSerializable类 [英] sendding List into a KvmSerializable class
问题描述
如何,我可以送的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:
- 对于这个类来创建对象马歇尔和
addMapping
它 - 实现接口
KvmSerializable
-
SoapObject
和矢量
默认序列化。
- Create marshall object for this class and
addMapping
for it - Implement interface
KvmSerializable
SoapObject
andVector
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屋!