我在加载GWT页面时遇到此错误:
错误com.google.gwt.user.client.rpc.SerializationException: Type 'com.summerbreezemotel.server.DBReservation'
未包含在可由此SerializationPolicy序列化的类型集中,或者无法加载其Class对象。
我查看了文档,似乎遵循了所有限制。我还有其他3个类做同样的事情但是这个似乎引起了一个问题。任何帮助将不胜感激。
failing:DBReservation
package com.summerbreezemotel.server;
import java.util.Date;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.summerbreezemotel.shared.DataReservation;
import com.summerbreezemotel.shared.SiteConstants;
public class DBReservation extends DataReservation
{
/**
*
*/
private static final long serialVersionUID = 146606067638056872L;
Date dateReserved;
String userEmail;
public DBReservation() {}
public DBReservation(DataReservation in) {
checkIn = in.checkIn;
checkOut = in.checkOut;
form_FirstName = in.form_FirstName;
form_LastName = in.form_LastName;
form_Addr1 = in.form_Addr1;
form_Addr2 = in.form_Addr2;
form_City = in.form_City;
form_State = in.form_State;
form_Zip = in.form_Zip;
form_Country = in.form_Country;
form_Phone = in.form_Phone;
form_Email = in.form_Email;
form_CardType = in.form_CardType;
form_CardMonth = in.form_CardMonth;
form_CardNumber = in.form_CardNumber;
form_CardYear = in.form_CardYear;
form_RoomType = in.form_RoomType;
form_isSmoking = in.form_isSmoking;
form_numRooms = in.form_numRooms;
ratePerNightPerRoom = in.ratePerNightPerRoom;
totalRate = in.totalRate;
}
DataReservation getData()
{
DataReservation out = new DataReservation();
out.checkIn = checkIn;
out.checkOut = checkOut;
out.form_FirstName = form_FirstName;
out.form_LastName = form_LastName;
out.form_Addr1 = form_Addr1;
out.form_Addr2 = form_Addr2;
out.form_City = form_City;
out.form_State = form_State;
out.form_Zip = form_Zip;
out.form_Country = form_Country;
out.form_Phone = form_Phone;
out.form_Email = form_Email;
out.form_CardType = form_CardType;
out.form_CardMonth = form_CardMonth;
out.form_CardNumber = form_CardNumber;
out.form_CardYear = form_CardYear;
out.form_RoomType = form_RoomType;
out.form_isSmoking = form_isSmoking;
out.form_numRooms = form_numRooms;
out.ratePerNightPerRoom = ratePerNightPerRoom;
out.totalRate = totalRate;
return out;
}
// gets item from DB and convertes it to this
void fillReservationFromEntity(Entity item)
{
userEmail = (String) item.getProperty(SiteConstants.USER_PROPERTY);
dateReserved = (Date) item.getProperty(SiteConstants.RESERVE_DATE_PROPERTY);
checkIn = (Date) item.getProperty(SiteConstants.IN_DATE_PROPERTY);
checkOut = (Date) item.getProperty(SiteConstants.OUT_DATE_PROPERTY);
form_FirstName = (String) item.getProperty(SiteConstants.FORM_FIRSTNAME_PROPERTY);
form_LastName = (String) item.getProperty(SiteConstants.FORM_LASTNAME_PROPERTY);
form_Addr1 = (String) item.getProperty(SiteConstants.FORM_ADDR1_PROPERTY);
form_Addr2 = (String) item.getProperty(SiteConstants.FORM_ADDR2_PROPERTY);
form_City = (String) item.getProperty(SiteConstants.FORM_CITY_PROPERTY);
form_State = (String) item.getProperty(SiteConstants.FORM_STATE_PROPERTY);
form_Zip = (String) item.getProperty(SiteConstants.FORM_ZIP_PROPERTY);
form_Country = (String)item.getProperty(SiteConstants.FORM_COUNTRY_PROPERTY);
form_Phone = (String) item.getProperty(SiteConstants.FORM_PHONE_PROPERTY);
form_Email = (String) item.getProperty(SiteConstants.FORM_EMAIL_PROPERTY);
form_CardType = (String) item.getProperty(SiteConstants.FORM_CARDTYPE_PROPERTY);
form_CardMonth = (String) item.getProperty(SiteConstants.FORM_CARDMONTH_PROPERTY);
form_CardNumber = (String) item.getProperty(SiteConstants.FORM_CARDNUMBER_PROPERTY);
form_CardYear = (Long) item.getProperty(SiteConstants.FORM_CARDYEAR_PROPERTY);
form_RoomType = (Long) item.getProperty(SiteConstants.FORM_ROOMTYPE_PROPERTY);
form_isSmoking = (Boolean) item.getProperty(SiteConstants.FORM_ISSMOKING_PROPERTY);
form_numRooms = (Long) item.getProperty(SiteConstants.FORM_NUMROOMS_PROPERTY);
ratePerNightPerRoom = (Double) item.getProperty(SiteConstants.RATEPERNIGHTPERROOM_PROPERTY);
totalRate = (Double) item.getProperty(SiteConstants.TOTALRATE_PROPERTY);
}
void addReservationsToEntity(Entity item)
{
item.setProperty(SiteConstants.USER_PROPERTY, userEmail);
item.setProperty(SiteConstants.RESERVE_DATE_PROPERTY, dateReserved);
item.setProperty(SiteConstants.IN_DATE_PROPERTY, checkIn);
item.setProperty(SiteConstants.OUT_DATE_PROPERTY, checkOut);
item.setProperty(SiteConstants.FORM_FIRSTNAME_PROPERTY,form_FirstName);
item.setProperty(SiteConstants.FORM_LASTNAME_PROPERTY,form_LastName);
item.setProperty(SiteConstants.FORM_ADDR1_PROPERTY,form_Addr1);
item.setProperty(SiteConstants.FORM_ADDR2_PROPERTY,form_Addr2);
item.setProperty(SiteConstants.FORM_CITY_PROPERTY,form_City);
item.setProperty(SiteConstants.FORM_STATE_PROPERTY,form_State);
item.setProperty(SiteConstants.FORM_ZIP_PROPERTY,form_Zip);
item.setProperty(SiteConstants.FORM_COUNTRY_PROPERTY,form_Country);
item.setProperty(SiteConstants.FORM_PHONE_PROPERTY,form_Phone);
item.setProperty(SiteConstants.FORM_EMAIL_PROPERTY,form_Email);
item.setProperty(SiteConstants.FORM_CARDTYPE_PROPERTY,form_CardType);
item.setProperty(SiteConstants.FORM_CARDMONTH_PROPERTY,form_CardMonth);
item.setProperty(SiteConstants.FORM_CARDNUMBER_PROPERTY,form_CardNumber);
item.setProperty(SiteConstants.FORM_CARDYEAR_PROPERTY,form_CardYear);
item.setProperty(SiteConstants.FORM_ROOMTYPE_PROPERTY,form_RoomType);
item.setProperty(SiteConstants.FORM_ISSMOKING_PROPERTY,form_isSmoking);
item.setProperty(SiteConstants.FORM_NUMROOMS_PROPERTY,form_numRooms);
item.setProperty(SiteConstants.RATEPERNIGHTPERROOM_PROPERTY,ratePerNightPerRoom);
item.setProperty(SiteConstants.TOTALRATE_PROPERTY,totalRate);
}
void store()
{
// UserService userService = UserServiceFactory.getUserService();
// User user = userService.getCurrentUser();
// if(user.getEmail() != null)
// userEmail = user.getEmail();
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
String SummerBreezeDateStoreName = new String(SiteConstants.KEY_NAME);
Key SummerBreezeDateStoreKey = KeyFactory.createKey(SiteConstants.KEY_KEY, SummerBreezeDateStoreName);
Entity reservationsEntry = new Entity(SiteConstants.DB_RESERVATIONS, SummerBreezeDateStoreKey);
addReservationsToEntity(reservationsEntry);
datastore.put(reservationsEntry);
// use this if writes get to high
// item.setProperty("testBlob",new Blob(toByte(roomResevationRequest)));
datastore.put(reservationsEntry);
}
}
我的DataReservation
package com.summerbreezemotel.shared;
import java.io.Serializable;
import java.util.Date;
public class DataReservation implements Serializable
{
private static final long serialVersionUID = -7598404617383692994L;
public String form_FirstName;
public String form_LastName;
public String form_Addr1;
public String form_Addr2;
public String form_City;
public String form_State;
public String form_Zip;
public String form_Country;
public String form_Phone;
public String form_Email;
public String form_CardType;
public String form_CardMonth;
public String form_CardNumber;
public long form_CardYear;
public long form_RoomType;
public boolean form_isSmoking;
public Date checkIn;
public Date checkOut;
public long form_numRooms;
public double ratePerNightPerRoom;
public double totalRate;
public DataReservation()
{
}
}
答案 0 :(得分:1)
您正在共享文件夹中使用一个文件来实现 Serializable 并在服务器端扩展它。你确定这个逻辑吗?它通常是客户端/共享端上的 pojo / dto / model 实现 IsSerializable 并将其发送到服务器。然后服务器执行操作并将其返回。
答案 1 :(得分:1)
我认为这是在脚下拍摄自己的典型案例。通过使用共享类中的逻辑扩展服务器对象,您可以更轻松地创建包含数据库代码的服务器端类,但如果您意外返回服务器端而不是在发送之前调用getData()
对于客户端,您获得的服务器端类当然不能发送给客户端。但是编译器不会因为语法正确而警告你。所以我认为答案不在给出的代码中,看起来不错,但是在gwt servlet和DBReservation
的用法之间。
答案 2 :(得分:0)
它应该实现Serializable接口。您不会通过扩展类来“继承”实现。