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?
something like:
{{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}}
and the Java:
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;
}
At the end I would like to access this json object as a data return from an ajax call. Is this possible?
I'm currently returning strings, but this is very inefficient how can I return objects?