I’m using GWT overlay types to parse my JSON response form the web server. It all works fine, the problem is, if the required field doesn’t exist:
example:
JavaScriupt overlay type class
public class JSWorkplace extends JavaScriptObject{
protected JSWorkplace() {
}
public final native String getWidgets() /*-{
return this.Widgets;
}-*/;
now if I have something like {“Widgets”:”Bla”} comes form the server everything is alright, getWidgets returns “Bla”.
If this “{}” comes from the server my application throws in the gwtWidgets function. How can I check if the field “Widgets” exists before reading it.
Regards,
Stefan
You can check if it’s undefined doing something like:
this.Widgets == undefined.Personally I prefer to set default values after the
eval(). For example, in order to create your JSWorkplace object I would invoke a method like this: