ksoap2-android序列化一个空数组

时间:2012-12-28 10:58:48

标签: android web-services ksoap2 webservice-client android-ksoap2

我想使用kso​​ap2在其中创建一个包含空列表的对象组。我设法使用webservice方法在独立应用程序上执行此操作,但是,使用android给我一个错误:java.lang.RuntimeException: Cannot serialize: []我的问题是,是否有一个解决此错误?

这是我的WSDL xml:

<xs:complexType name="createGroup">
<xs:sequence>
<xs:element name="new-group-object" type="tns:group" minOccurs="0"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="group">
<xs:sequence>
<xs:element name="groupId" type="xs:long"/>
<xs:element name="groupName" type="xs:string" minOccurs="0"/>
<xs:element name="users" type="tns:user" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="user">
<xs:sequence>
<xs:element name="latitude" type="xs:double"/>
<xs:element name="longitude" type="xs:double"/>
<xs:element name="userAge" type="xs:int"/>
<xs:element name="userId" type="xs:long"/>
<xs:element name="userName" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>

和我的android客户端方法:

public void createGroupServ(String groupName) 
{
    request = new SoapObject(NAMESPACE, "createGroup");
    SoapObject soapGroup = new SoapObject(NAMESPACE, "group");

    Group gr = new Group();
    gr.setGroupName(groupName);
    gr.setUsers(new ArrayList<User>());
    request.addProperty("new-group-object", gr);

    envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = false;
    envelope.setOutputSoapObject(request);

    androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.debug = true;
      ... 
    }

1 个答案:

答案 0 :(得分:0)

您需要为组和用户实现KvmSerializable接口。阅读文章: java.lang.RuntimeException: Cannot serialize: MyClass

http://www.sgoliver.net/blog/?p=2594

我建议升级到ksoap的最新版本,因为您可能需要使用: http://seesharpgears.blogspot.com/2010/11/implementing-ksoap-marshal-interface.html 对于您的双数据类型

相关问题