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.DelegatingChangeListenerCollection 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.DelegatingClickListenerCollection 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.DelegatingFocusListenerCollection 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.DelegatingKeyboardListenerCollection 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.