GWT: response cannot be deserialized

I am using GWT (2.4) with Spring integrated, as in this article . I have a problem getting a list of users from a database (Hibernate) and populating a DataGrid. When I call the greetingService.allUsers() method, I get an error (onFailure ()):

com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException: Response cannot be deserialized

Does anyone help with this? Below are some code snippets. Full working draft here .

  public void onModuleLoad() { // ... greetingService.allUsers( new AsyncCallback<List<User>>(){ @Override public void onFailure(Throwable caught) { caught.printStackTrace(); } @Override public void onSuccess(List<User> result) { GWT.log("SIZE: "+result.size()); dataGrid.setRowData(result); } } ); // ... } 

GreetingServiceImpl

 @Override public List<User> allUsers() { return userDAO.findAll(); } 

User

 @Entity @Table(name = "users") public class User implements Serializable, IsSerializable { @Id private Long id; // only Strings and one Date private String login; private String password; private String firstname; private String lastname; private Date date; } 
+6
source share
8 answers

I solved my problem by updating the GwtRpcController accordingly. Now deserialization works well without using any transfer object. GwtRpcController below.

 import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.context.ServletContextAware; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; import com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.SerializationException; import com.google.gwt.user.server.rpc.RPC; import com.google.gwt.user.server.rpc.RPCRequest; import com.google.gwt.user.server.rpc.RemoteServiceServlet; public class GwtRpcController extends RemoteServiceServlet implements Controller, ServletContextAware { private static final long serialVersionUID = 1L; private ServletContext servletContext; private RemoteService remoteService; private Class remoteServiceClass; public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { super.doPost(request, response); return null; } @Override public String processCall(String payload) throws SerializationException { try { RPCRequest rpcRequest = RPC.decodeRequest(payload, this.remoteServiceClass, this); onAfterRequestDeserialized(rpcRequest); // delegate work to the spring injected service return RPC.invokeAndEncodeResponse(this.remoteService, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy()); } catch (IncompatibleRemoteServiceException ex) { getServletContext().log("An IncompatibleRemoteServiceException was thrown while processing this call.", ex); return RPC.encodeResponseForFailure(null, ex); } } @Override public ServletContext getServletContext() { return servletContext; } @Override public void setServletContext(ServletContext servletContext) { this.servletContext = servletContext; } public void setRemoteService(RemoteService remoteService) { this.remoteService = remoteService; this.remoteServiceClass = this.remoteService.getClass(); } } 
+1
source

Documentation for IncompatibleRemoteServiceException:

This exception may be caused by the following problems:

  • The requested {@link RemoteService} cannot be found via {@link Class # forName (String)} on the server.
  • The requested {@link RemoteService Interface} is not implemented {@link com.google.gwt.user.server.rpc.RemoteServiceServlet RemoteServiceServlet}, which is configured to process the request.
  • The requested service method is undefined or inherited by the requested interface {@link RemoteService}.
  • One of the types used in the {@link RemoteService} method of the user has added or removed fields.
  • Client code receives a type from the server, which it cannot deserialize.

In your case, this is the last point, you have a type that cannot be serialized and deserialized, that your User class is one of them. You must have one transfer object that implements the com.google.gwt.user.client.rpc.IsSerializable interface to transfer the User object over the network. For more information, see Java and Library Compatibility . The parameters of the GWT RPC method and the types of returned data must be transmitted over the network between client and server applications, so they must be serializable .

+6
source

I would try a couple of things.

  • User only implements com.google.gwt.user.client.rpc.IsSerializable and an empty constructor is added. I remember somewhere I read for a long time that it is necessary, and in one of my projects he solved such a problem. public User () {}
  • Make sure your package is defined in the gwt.xml file.

You are not doing anything more complicated that cannot be serialized, so you should be fine with this.

+2
source

That's all, Spent a lot of time with this, and I have a different solution. I used a very simple setup, and my POJOs were really no more than those members and CTORs.

I recreated a new GWT project and added my stuff back to the new project, adding every POM.xml dependency. I found that the maven compiler was too high. I copied this from another project without thinking about it ... The client side of GWT is almost only 1.5, maybe compatible with 1.6 ... so these parameters should be set to 1.5, not 1.7

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.7</source> <!-- change these to 1.5 --> <target>1.7</target> </configuration> </plugin> 
0
source

I had this error when using guava-gwt with scope provided. To satisfy runtime dependencies, I added google compilations. The GWT client was unable to deserialize them.

Solution: remove google-dependent assemblies and stick with guava.

0
source

For problems with serializable objects, you can try this checklist:

  • Make sure the class has a default constructor (no arguments)
  • Make sure that the class implements Serializable or IsSerializable or implements an interface that extends Serializable or extends the class that implements Serializable
  • Make sure the class is in the client. * package or ...
  • Check if the class is not in the client. * package, which is compiled into your XML GWT module definition. By default is present. If your class is in another package, you should add it to the source code. For example, if your class is in a domain. * You must add it to xml as. Be aware that the class cannot belong to the server package! Learn more about the GWT page: http://code.google.com/webtoolkit/doc/latest/DevGuideOrganizingProjects.html#DevGuideModuleXml
  • If you include a class from another GWT project, you must add inheritance to your xml module definition. For example, if the class Foo is in the package com.dummy.domain, which you must add to the module definition. More details here: http://code.google.com/webtoolkit/doc/latest/DevGuideOrganizingProjects.html#DevGuideInheritingModules
  • If you included a class from another GWT project that was released as a jar, verify that the jar also contains the source code, because GWT also recompiles the Java source for the classes passed to the client.

Font: http://isolasoftware.it/2011/03/22/gwt-serialization-policy-error/

0
source

I work in a team with mature software that once stopped working for me due to this error. The rest of the team was fine. We tried any number of things to fix it. In the end, we reinstalled IntelliJ and fixed it.

0
source

Sometimes this error can be caused by outdated / damaged files / caches on the client side (in this case, there is no error message on the server side). I just ran the "rebuild module" module in IntelliJ and everything was fine.

0
source

Source: https://habr.com/ru/post/906485/


All Articles