Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
2.1-M4以上Restlet版本的Java序列化问题_Java_Android_Serialization_Restlet - Fatal编程技术网

2.1-M4以上Restlet版本的Java序列化问题

2.1-M4以上Restlet版本的Java序列化问题,java,android,serialization,restlet,Java,Android,Serialization,Restlet,我正在尝试运行这里提供的非常简单的Restlet示例应用程序 我试图在Android设备上运行客户端,但出现以下错误: Unable to convert a [application/json,UTF-8] representation into an object of class org.restlet.example.common.Contact java.io.IOException: Unable to create the Object representation org.res

我正在尝试运行这里提供的非常简单的Restlet示例应用程序

我试图在Android设备上运行客户端,但出现以下错误:

Unable to convert a [application/json,UTF-8] representation into an object of class org.restlet.example.common.Contact
java.io.IOException: Unable to create the Object representation
org.restlet.engine.converter.DefaultConverter.toObject(DefaultConverter.java:291)
org.restlet.service.ConverterService.toObject(ConverterService.java:170)
org.restlet.resource.Resource.toObject(Resource.java:828)
org.restlet.engine.resource.ClientInvocationHandler.invoke(ClientInvocationHandler.java:240)
$Proxy7.retrieve(Native Method)
org.restlet.example.serialisation.android.activity.ContactActivity$2.run(ContactActivity.java:142)
java.lang.Thread.run(Thread.java:1096)
java.lang.IllegalArgumentException: The serialized representation must have this media type: application/x-java-serialized-object or this one: application/x-java-serialized-object+xml
org.restlet.representation.ObjectRepresentation.<init>(ObjectRepresentation.java:204)
org.restlet.representation.ObjectRepresentation.<init>(ObjectRepresentation.java:133)
org.restlet.representation.ObjectRepresentation.<init>(ObjectRepresentation.java:114)
org.restlet.engine.converter.DefaultConverter.toObject(DefaultConverter.java:288)
无法将[application/json,UTF-8]表示转换为org.restlet.example.common.Contact类的对象
java.io.IOException:无法创建对象表示
org.restlet.engine.converter.DefaultConverter.toObject(DefaultConverter.java:291)
org.restlet.service.ConverterService.toObject(ConverterService.java:170)
org.restlet.resource.resource.toObject(resource.java:828)
org.restlet.engine.resource.ClientInvocationHandler.invoke(ClientInvocationHandler.java:240)
$Proxy7.retrieve(本机方法)
org.restlet.example.serialization.android.activity.ContactActivity$2.run(ContactActivity.java:142)
run(Thread.java:1096)
java.lang.IllegalArgumentException:序列化表示必须具有以下媒体类型:application/x-java-serialized-object或此媒体类型:application/x-java-serialized-object+xml
ObjectRepresentation.org.restlet.representation.ObjectRepresentation.(ObjectRepresentation.java:204)
ObjectRepresentation.org.restlet.representation.ObjectRepresentation.(ObjectRepresentation.java:133)
ObjectRepresentation.org.restlet.representation.ObjectRepresentation.(ObjectRepresentation.java:114)
org.restlet.engine.converter.DefaultConverter.toObject(DefaultConverter.java:288)
使此应用程序工作的唯一方法是使用Restlet 2.1-M4版本。我尝试了2.2-RC2,甚至“稳定”的2.1.7 Restlet版本

我知道该应用程序已经用“Restlet Framework 2.1里程碑4”进行了测试,但对于我来说,像2.1.7这样的更高稳定版本在这样一个简单的例子上疯了,这听起来太奇怪了

这个应用程序本身非常简单,除了restlet库本身的一个“bug”之外,我看不出这个问题会发生在哪里。 我能想象的唯一其他选择是,在restlet 2.1-m4之后,为了让java序列化正常工作,必须在客户端和/或服务器中添加一些2.1-m4不需要的额外代码

如有任何意见或建议,将不胜感激

最好的


由于潜在的安全问题,我们不得不禁用默认转换器,如下所述:


您应该将Jackson扩展添加到类路径(org.restlet.ext.Jackson.jar和依赖项)。希望这能有所帮助。

非常感谢Jerome,所以我需要做的就是在我的类路径中添加org.restlet.ext.jackson.jar?我还需要在java源代码中显式设置Jackson转换器吗?另外,请您更准确地了解:org.restlet.ext.jackson.jar需要哪些库?谢谢你的支持!Jerome Louvel,你能详细说明你的答案吗。我也面临这个问题。加入杰克逊的罐子没有任何帮助。我应该修改java代码以强制使用jackson吗?如果通过Maven配置jackson扩展,所有依赖项都会自动出现。如果使用Zip发行版,则会有一个/lib/readme.txt文件列出所有依赖项。正如我建议的那样,我添加了org.restlet.ext.jackson(Maven),但这并没有帮助。。。我现在如何启动和运行我的客户?我试图通过JSON将序列化对象发布到我的GAE服务器。