Here is an example which might help you... First Let us look at this code snippet
public class SimpleRestClass extends BaseWebServiceServlet {
private static final long serialVersionUID = 1L;
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
String Name = request.getParameter("Name");
String Email = request.getParameter("Email");
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("Name", Name);
map.put("Email", Email);
// map.put("Path", request.getPathInfo().toString());
list.add(map);
final String json = new DataToJsonConverter().convertToJsonObjects(list).toString();
// write to the response
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
final Writer w = response.getWriter();
w.write(json);
w.close();
}
}
In the above code
final String json = new DataToJsonConverter().convertToJsonObjects(list).toString();
is what you are looking for. The signature of convertToJsonObjects() method is
List<JSONObject> convertToJsonObjects(List<Map<String, Object>> data)
The important class in openbravo for REST Json WS to notice is
import org.openbravo.service.json.DataToJsonConverter
This class has many more Json related methods. Hope this will help you.
If you have any questions then please feel free to ask.