我无法找到两个(不同类)对象中的一个无法序列化/反序列化的原因。
LoginRequestProtocol对象被发送到我的服务器,反序列化,我的服务器开始处理请求。请求被提交后不久,我正在尝试发送响应,这就是失败的地方。我错过了什么?
第一个发送没有任何问题的对象:
public class LoginRequestProtocol implements Serializable{
private static final long serialVersionUID = 1L;
public final LoginRequest REQUEST;
private String[] body = null;
public LoginRequestProtocol(LoginRequest type) {
REQUEST = type;
}
public boolean setRequestBody(String... args) {
Log.debug("Setting LoginProtocolRequest body...", 0);
if (args.length > 0) {
body = args;
Log.debug(" body size: " + body.length + ".", 1);
return true;
} else {
Log.debug(" failure.", 0);
Log.warning("Data passed for the body was empty.");
return false;
}
}
public String[] getRequestBody() {
Log.debug("Extracting LoginProtocolRequest body...", 0);
if (body == null || body.length < 1) {
Log.debug(" failure.", 1);
Log.warning("Data passed for the body was empty.");
return null;
} else {
Log.debug(" body size: " + body.length + ".", 1);
return body;
}
}
}
第二个对象 - LoginResponseProtocol无法执行此操作。
package common.network;
import java.io.Serializable;
public class LoginResponseProtocol implements Serializable{
private static final long serialVersionUID = 1L;
public final LoginResponse RESPONSE;
public LoginResponseProtocol(LoginResponse response) {
RESPONSE = response;
}
}
注意:LoginRequest和LoginResponse是枚举。
服务器说:
java.io.NotSerializableException: common.network.LoginResponseProtocol
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
客户说:
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: common.network.LoginResponseProtocol
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
更新:LoginResponse:
package common.network;
public enum LoginResponse {
OK,
ERROR_CONNECTION,
ERROR_SQL,
FAIL
}