无法序列日期与ksoap2 [英] Cannot serialize dates with ksoap2

查看:210
本文介绍了无法序列日期与ksoap2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不管是什么格式我尝试,我无法从我的Andr​​oid(Java)的应用程序到.NET Web服务发送日期。我试着发送它作为一个的GregorianCalendar ,一个日期,一个日历 ...没有什么工作。

我得到一个不能被序列化的错误作为一个运行时异常。我使用kso​​ap2来管理我的Web服务调用。任何想法?

以下错误:

 了java.lang.RuntimeException:无法序列:java.util.GregorianCalendar中...
java.lang.RuntimeException的:无法序列:java.util.Date ...
 

解决方案

最终通过几个死角管理,跟踪下来。看来KSOAP库不知道做什么用日期或双打将通过对Web服务调用发送 - 你需要告诉它如何处理它们,或者得到一个序列化错误

要做到这一点的方法是实施 MarshalDate 类:的本教程有code,你需要实现它。

这是我的经验,ksoap2具有 MarshalDate 类已经在图书馆和该类将做的工作,但不反对信封默认注册。通过注册它靠在信封(如下图),这个问题就解决了​​。双打或其他浮点数,使用 MarshalFloat 代替。

要解决这个问题,你送之前,你的 SoapSerializationEnvelope 通过 HttpTransport 做这样的判断:

 新MarshalDate()寄存器(信封);
 

其中,信封 SoapSerializationEnvelope

我发现了ksoap2库具有 MarshalDate MarshallFloat 导入类意外上课的时候​​,作为Eclipse的为我提供了两种选择将其导入 - 其中之一是内ksoap2。所包含的类就够了,我打消了我的自定义的。

No matter what format I try, I can't send a date from my Android (Java) app to the .NET web service. I've tried sending it as a GregorianCalendar, a Date, a Calendar... Nothing works.

I get a "cannot be serialized" error as a runtime exception. I'm using ksoap2 to manage my web service calls. Any ideas?

Errors below:

java.lang.RuntimeException: Cannot serialize: java.util.GregorianCalendar...
java.lang.RuntimeException: Cannot serialize: java.util.Date...

解决方案

Managed to track this down eventually through several dead ends. It seems the ksoap library doesn't know what to do with dates or doubles to be sent through on the webservice call - you need to tell it how to handle them or it gets a serialization error.

The way to do this is to implement the MarshalDate class: this tutorial has the code you need to implement it.

From my experiences, ksoap2 has the MarshalDate class already in the library and that class will do the job, but doesn't register it against the envelope by default. By registering it against the envelope (as below), the problem was resolved. For doubles or other floating point numbers, use MarshalFloat instead.

To fix this problem, before you send your SoapSerializationEnvelope through your HttpTransport make this call:

new MarshalDate().register(envelope);

where envelope is your SoapSerializationEnvelope.

I found out the ksoap2 library has the MarshalDate and MarshallFloat classes by accident when importing the class, as Eclipse provided me with two options for importing it - one of which was within ksoap2. The included class sufficed and I removed my custom one.

这篇关于无法序列日期与ksoap2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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