So thx you @xi-chen and @richard-wallis
Part of the solution were discussed on gwt-storage github repo (https://github.com/seanchenxi/gwt-storage/issues/8#issuecomment-68443910)
So it's totally possible with GWT RPC mechanism + gwt-storage:
index.jsp
<%@page import="com.google.gson.Gson"%>
<%@page import="com.learnkeeper.server.ServiceImpl"%>
<%@page import="com.google.gwt.user.server.rpc.RPC"%>
<%@page import="com.learnkeeper.shared.entities.User"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<%
Object user = request.getSession().getAttribute("user");
String serialized_user = new Gson().toJson(RPC.encodeResponseForSuccess(ServiceImpl.class.getMethod("getUser"), user).substring("//OK".length()));
%>
<script type="text/javascript">var serialized_user=<%=serialized_user%>;</script>
</head>
<body>
Notice you have to remove the //OK substring at the beginning of RPC.encodeResponseForSuccess result.
User.java
public class User implements IsSerializable {
}
Notice you have to implement IsSerializable (Serializable is not enough)
HostPageUtils.java
public class HostPageUtils {
private static final native String getSerializedUser() /*-{
return $wnd.serialized_user;
}-*/;
public static User getUser() {
final String serializedUser = getSerializedUser();
StorageSerializer storageSerializer = GWT.create(StorageSerializer.class);
try {
return storageSerializer.deserialize(User.class, serializedUser);
} catch (Exception e) {
throw new RuntimeException();
}
}
}