I’ve moved my application from Vaadin 7.3.10 to Vaadin 7.4.3. After adjusting the new dependencies, and replacing references from “org.json” to “elemental.json”, my custom AbstractJavaScriptComponent seems to have problems to convert Java types to Javascript types when calling the “callFunction(…)” method.
public class JsMap extends AbstractJavaScriptComponent {
private static final long serialVersionUID = 1L;
public JsMap() {
super();
}
public void drawDevices(List<Integer> identifiers, List<List<String>> dataStrings, List<List<Double>> locations, List<Integer> connectionsStatus, List<Boolean> errorsStatus)
{
callFunction("drawDevices", identifiers, dataStrings, locations, connectionsStatus, errorsStatus);
}
}
Seems that Vaadin doesn’t like List<List<…>> anymore, throwing this exception:
abr 07, 2015 8:07:58 AM com.vaadin.server.DefaultErrorHandler doDefault
GRAVE:
elemental.json.JsonException: Collection is missing generics
at com.vaadin.server.JsonCodec.encodeChild(JsonCodec.java:900)
at com.vaadin.server.JsonCodec.encodeCollection(JsonCodec.java:884)
at com.vaadin.server.JsonCodec.encode(JsonCodec.java:665)
at com.vaadin.server.JsonCodec.encodeArrayContents(JsonCodec.java:873)
at com.vaadin.server.JsonCodec.encode(JsonCodec.java:688)
at com.vaadin.server.JavaScriptCallbackHelper.invokeCallback(JavaScriptCallbackHelper.java:97)
at com.vaadin.ui.AbstractJavaScriptComponent.callFunction(AbstractJavaScriptComponent.java:181)
at es.ccu.teseo.web.component.JsMap.drawDevices(JsMap.java:50)
at es.ccu.teseo.web.ui.view.MapView.refreshMap(MapView.java:443)
at es.ccu.teseo.web.ui.view.MapView.loadData(MapView.java:336)
Hello Antonio, I found the same problem still in Vaadin 7.4.7
I narrowed the problem to the following to the method com.vaadin.server.JsonCodec::encodeChild
I opted for replacing the method with my own version:
There’s faster way—probably it’s not a bug—only problem is that it’s not described enough!
Change your code as follows (cf.
stackoverflow.com ): for field and method parameters/returned value (provided they’re in fact types with parameters!) you may use
Field field = …
ParametrizedType type = (ParameterizedType) field.getGenericType();
and
Method method = …
int parameterNo = 1; // first parameter
type = (ParameterizedType) method.getGenericParameterTypes()[parameterNo - 1]
;
and
Method method = …
ParametrizedType type = (ParametrizedType) method.getGenericReturnType();
For example if you have
arguments of class
List then this class is refered to as
type above/belowe and
String is
parameterType below. If you have type in superclass (e.g. java
Collection ) you might even use: