我创建了一个 CN1 Web 服务,其中一些我想要外部化以便通过网络发送的自定义对象。我阅读了几篇关于如何创建 Web 服务以及如何使用 CN1 Externalizable 接口的文章。
这适用于返回自定义可外部化对象的 Web 服务方法,但是我拥有的唯一指标是将可外部化对象作为参数的方法,我收到以下错误:
SCHWERWIEGEND: Servlet.service() for servlet [CN1WebServiceServlet]
in context with path [/<myPath>] threw exception
java.io.IOException: Object type not supported: Post
该对象已正确注册到 Util 类,因为更改对象 ID 或注释掉注册调用将导致空指针而不是 IO 异常。
Post 类看起来像这样(简化到已经失败的最小值):
public class Post implements Externalizable {
public int postid;
public int userid;
// default constructor needed for web service marshalling
public Post() {
}
@Override
public int getVersion() {
return 1;
}
@Override
public void externalize(DataOutputStream out) throws IOException {
Util.writeUTF("" + postid, out);
Util.writeUTF("" + userid, out);
}
@Override
public void internalize(int version, DataInputStream in) throws IOException {
this.postid = Integer.parseInt(Util.readUTF(in));
this.userid = Integer.parseInt(Util.readUTF(in));
}
@Override
public String getObjectId() {
return "Post";
}
请注意,当我调用返回 post 对象的 Web 服务方法时,此 Post 对象运行良好,但当我将 Post 对象发送到 Web 服务时则不行:
// works
public static com.codename1.io.Externalizable getPostDetails(int postid) {
return getPostDetails(postid);
}
// fails
public static void sendPost(com.codename1.io.Externalizable post) {
sendPost(post);
}
我不知道我在这里错过了什么。
谢谢和最好的问候