Re: Using Object in classes passed via GWT RPC
Hi James,
-- in general you should try to avoid to pass any class over GWT-RPC to the client which has a member of type 'Object'.
The reason:
The GWT-RPC compiler doesn't know which type will be passed during the run-time. So it will create serializer and de-serializer for all classes which are in you source path and which extends the class object. So maybe a lot of unnecessary code will be generated and maybe not all class which extends Object can be serialized by GWT.
So in your case it would be mach better to introduce an interface 'CalculationValue' and provide 4 implementation with the different value types.
And you will see that it compiles faster and it should work much better :)
BR
Rocco
Am Freitag, 8. November 2013 19:37:37 UTC+1 schrieb James Clough:
Am Freitag, 8. November 2013 19:37:37 UTC+1 schrieb James Clough:
I am trying to return the result of a calculation from an RPC call, and having trouble with the GWT compiler. Specifically, the class I am returning has a field of type Object in it. This field can contain: String, Integer, Double, Long, Boolean or Date.If I change the Object field to type String, the compiler is happy.The thing that has me stumped is that I have other methods in the same RPC service that return similar objects containing Object fields and these are working correctly. I also have an RPC-based event mechanism that is returning event classes that contain Map<String,Object> and these appear to work correctly. I of course have to have another interface (a whitelist) that refers to the types I want to return in the Object fields to get serialization code generated for those types.Am I doing something wrong? I see the documentation says I can't return Object, but it's been working for a couple of years.Is there a better way to accomplish this?Here's the class of the object I'm trying to return:public class CalculationResult implements Serializable {private static final long serialVersionUID = 1L;private Object value = null;private PropertyType type;private List<LocalizedMessage> errors;public CalculationResult() {super();}public Object getValue() {return value;}public void setValue(Object value) {this.value = value;}public PropertyType getType() {return type;}public void setType(PropertyType type) {this.type = type;}public List<LocalizedMessage> getErrors() {if( this.errors == null ) {this.errors = new ArrayList<LocalizedMessage>();}return this.errors;}public void setErrors(List<LocalizedMessage> errors) { this.errors = errors;}}PropertyType is a simple enum.LocalizedMessage is a serializable class containing only String and List<String> fields and is used extensively in other RPC calls.When I compile my project with GWTC, I get the following:[java] Compiling module com.XX.XXXXXXXXXXXXXXXXXXXXXXXXXXx [java] Computing all possible rebind results for 'com.XX.gwt.ui.client.rpc.PMRPCService' [java] Rebinding com.XX.gwt.ui.client.rpc.PMRPCService [java] Invoking generator com.google.gwt.user.rebind.rpc. ServiceInterfaceProxyGenerator [java] Generating client proxy for remote service interface 'com.XX.gwt.ui.client.rpc.PMRPCService' [java] Checking type argument 0 of type 'java.util.Arrays.ArrayList<E>' because it is exposed as an array with a maximum dimension of 1 in this type or one of its subtypes (reached via com.XX.core.resources.calculation.CalculationResult) [java] [ERROR] com.google.gwt.editor.client.adapters.ListEditorWrapper<T, E> is not default instantiable (it must have a zero-argu ment constructor or no constructors at all) and has no custom serializer. (reached via com.XX.core.resources.calculation.CalculationResult) [java] [ERROR] com.google.gwt.user.client.ui.DelegatingChangeListenerCollec tion is not default instantiable (it must have a zero-a rgument constructor or no constructors at all) and has no custom serializer. (reached via com.XX.core.resources.calculation.CalculationResult) [java] [ERROR] com.google.gwt.user.client.ui.DelegatingClickListenerCollect ion is not default instantiable (it must have a zero-ar gument constructor or no constructors at all) and has no custom serializer. (reached via com.XX.core.resources.calculation.CalculationResult) [java] [ERROR] com.google.gwt.user.client.ui.DelegatingFocusListenerCollect ion is not default instantiable (it must have a zero-ar gument constructor or no constructors at all) and has no custom serializer. (reached via com.XX.core.resources.calculation.CalculationResult) [java] [ERROR] com.google.gwt.user.client.ui.DelegatingKeyboardListenerColl ection is not default instantiable (it must have a zero -argument constructor or no constructors at all) and has no custom serializer. (reached via com.XX.core.resources.calculation.CalculationResult) [java] [ERROR] com.google.gwt.view.client.ListDataProvider<T>. ListWrapper<> is not default instantiable (it must have a zero-argum ent constructor or no constructors at all) and has no custom serializer. (reached via com.XX.core.resources.calculation.CalculationResult) [java] [ERROR] com.google.web.bindery.autobean.shared.impl. SplittableList<E> is not default instantiable (it must have a zero-argu ment constructor or no constructors at all) and has no custom serializer. (reached via com.XX.core.resources.calculation.CalculationResult) [java] [ERROR] java.util.AbstractList.SubList<E> is not default instantiable (it must have a zero-argument constructor or no const ructors at all) and has no custom serializer. (reached via com.XX.core.resources.calculation.CalculationResult) [java] [ERROR] java.util.Collections.UnmodifiableList<T> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.XX.core.resources.calculation.CalculationResult) [java] [ERROR] java.util.Collections.UnmodifiableRandomAccessList< T> is not default instantiable (it must have a zero-argument con structor or no constructors at all) and has no custom serializer. (reached via com.XX.core.resources.calculation.CalculationResult) [java] [ERROR] Errors in 'com/XX/gwt/ui/client/ClientFactoryImpl.java' [java] [ERROR] Line 327: Failed to resolve 'com.XX.gwt.ui.client.rpc.PMRPCService' via deferred binding This error seems to be having trouble with the list, but if I simply remove the Object field or change it to String, these go away, too.
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home