Get JSON data from JAVA component to XWiki apache velocity
<p>What is the best way to get JSON data from a java component in xwiki runnung apache. In my java
component I'm compiling JSONObjects and JSONArrays, I would like to return
this data to my velocity script in JSON format, is this possible?</p>

<p>something like:</p>

<pre><code>{{velocity wiki="false"}}
    #if("$!request.outputSyntax" != '')
      $response.setContentType('application/json')
    #end
    #set($map = {})
    #set ($rightIN =  ${request.rightIN})
    #set ($spacenameIN =  ${request.spacenameIN})
#set($disgard =$map.add($services.getjsondata.javacomp($spacenameIN,$rightIN)))
    $jsontool.serialize($map)
 {{/velocity}}
</code></pre>

<p>and the Java:</p>

<pre><code>      public JSONObject javacomp(String spacenameIN, String rightIN ){
              JSONObject obj = new JSONObject();
              try {
                    obj.put("spacenameIN ", spacenameIN );
                    obj.put("rightIN", rightIN );
            } catch (JSONException e) {
                    e.printStackTrace();
            }
              return obj;
      }
</code></pre>

<p>At the end I would like to access this json object as a data return from an
ajax call. Is this possible?</p>

<p>I'm currently returning strings, but this is very inefficient how can I return objects? </p>