【问题标题】:Abstract class with gwt and serializable?具有gwt和可序列化的抽象类?
【发布时间】:2018-10-30 10:12:51
【问题描述】:

早安,

我在英语 (:D) 和 GWT 方面遇到了很多问题。

在 GWT 中,抽象类可以序列化吗?

这是我关于 ElectionOnline 项目的代码。非常感谢你的帮助。

package elezione.eco.shared;

public abstract class User 
{
	protected String username;
	protected String password;
	protected String email;
	protected String name;
	protected String surname;
	protected String sex;
	protected String birthDate;
	protected String birthPlace;
	protected String address;
	
	public User(){}
	
	
	public String getName() {
		return name;
	}

	public String getSurname() {
		return surname;
	}

	public String getSex() {
		return sex;
	}

	public String getBirthDate() {
		return birthDate;
	}

	public String getBirthPlace() {
		return birthPlace;
	}

	public String getAddress() {
		return address;
	}

	public String getUsername(){
		return username;
	}
	
	public String getPassword(){
		return password;
	}
	
	public String getEmail(){
		return email;
	}	

}

package elezione.eco.server;

import elezione.eco.client.ECOService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import elezione.eco.shared.*;

import java.io.File;
import java.util.ArrayList;

import org.mapdb.DB;
import org.mapdb.DBMaker;

/**
 * The server-side implementation of the RPC service.
 */
public class ECOServiceImpl extends RemoteServiceServlet implements ECOService {
	
	private static final long serialVersionUID = 1L;
	LoginServiceImpl loginService;
	
	public ECOServiceImpl() {
		DB db = DBMaker.newFileDB( new File( "ECO-DB.txt" ) ).closeOnJvmShutdown().make();

		loginService = new LoginServiceImpl( db );
	}
	
	public void restartDb() {
		loginService.clear();		
		loginService.addAdmin();
	}
	
	public void populate() {

		try {
			addUser( "Sergio" , "m" , "sergio@studio.it" , null , null , null , null , null , null );
		} catch ( DuplicatedUserNameException e ) {
			e.printStackTrace();
		}
	}
	
	public User addUser( String username, String password, String email, String name, String surname, String sex,
			String birthDate, String birthPlace, String address ) throws DuplicatedUserNameException {
		return loginService.addUser( username , password , email , name , surname , sex , birthDate , birthPlace ,
				address );
	}

	public User login( String userName, String password ) throws WrongPasswordException, UserNotFoundException {
		return loginService.login( userName , password );
	}
	
	public ArrayList<User> getRegistered() {
		return loginService.getRegistered();
	}
	
	public ArrayList<User> getAllUsers() {
		return loginService.getAllUsers();
	}
}

好吧,我不明白,因为 gwt 使用可序列化编译错误。类抽象可以序列化吗?我必须实现模式摘要。谢谢

【问题讨论】:

  • 您不能创建抽象类的实例。您必须为抽象类提供 Child 类,以便 GWT 服务可以创建实例并对其进行序列化

标签: java class serialization gwt interface


【解决方案1】:

GWT(具体为 GWT-RPC)支持序列化 IsSerializable 类,该类扩展抽象可序列化类。

如果您正在寻找在客户端没有特定实现的 DTO 类,您正在寻找 ProxyRequestFactory

http://www.gwtproject.org/doc/latest/DevGuideRequestFactory.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 2010-10-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多