title: Passing an arbitrary JSONValue to a JSNI function
body: <p>I have a JSONValue in my Java that may be a JSONArray, a JSONObject, a JSONString, etc.  I want to pass it to a JSNI function that can accept any of those types.  If I naively write my JSNI as something like:</p>
  
  <pre><code>public final native jsni(Object parameter) /*-{
      doSomething(parameter);
  }-*/;
  
  public void useFunction(JSONValue value) {
      jsni(value);  //Throws js exception at runtime :(
  }
  </code></pre>
  
  <p>then I get a javascript exception, because GWT doesn't know how to convert the JSONValue to a JavaScriptObject (or native string / number value).</p>
  
  <p>My current workaround is</p>
  
  <pre><code>public final native jsniForJSO(Object parameter) /*-{
    doSomething(parameter);
  }-*/;
  
  public final native jsniForString(String parameter) /*-{
    doSomething(parameter);
  }-*/;
  
  public final native jsniForNumber(double parameter) /*-{
    doSomething(parameter);
  }-*/;
  
  public actuallyUseFunction(JSONValue value) {
    if (value.isObject()) {
      jsniForJSO(value.isObject().getJavaScriptObject());
    } else if (value.isString()) {
      jsniForString(value.isString().stringValue());
    } else {
      //etc
    }
  }
  </code></pre>
  
  <p>This is a big burden for code maintainability, etc... <em>especially</em> if you have more than one parameter.  Is there a way to generate these functions automatically, or get around this issue altogether?  I've taken to wrapping everything in a JSONObject first, so I can definitely get a JavaScriptObject to pass to my jsni, but that's another clumsy mechanic.</p>