| | |
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | |
|
| | | import com.gitblit.utils.JsonUtils;
|
| | | import com.gitblit.utils.StringUtils;
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.GsonBuilder;
|
| | |
|
| | | /**
|
| | | * Servlet class for interpreting json requests.
|
| | |
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | protected final int forbiddenCode = HttpServletResponse.SC_FORBIDDEN;
|
| | | |
| | | protected final int notAllowedCode = HttpServletResponse.SC_METHOD_NOT_ALLOWED;
|
| | |
|
| | | protected final int failureCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
|
| | | |
| | | protected final Logger logger;
|
| | |
|
| | | public JsonServlet() {
|
| | |
| | | return null;
|
| | | }
|
| | |
|
| | | Gson gson = new Gson();
|
| | | X object = gson.fromJson(json.toString(), clazz);
|
| | | X object = JsonUtils.fromJsonString(json.toString(), clazz);
|
| | | return object;
|
| | | }
|
| | |
|
| | |
| | | return null;
|
| | | }
|
| | |
|
| | | Gson gson = new Gson();
|
| | | X object = gson.fromJson(json.toString(), type);
|
| | | X object = JsonUtils.fromJsonString(json.toString(), type);
|
| | | return object;
|
| | | }
|
| | |
|
| | |
| | | protected void serialize(HttpServletResponse response, Object o) throws IOException {
|
| | | if (o != null) {
|
| | | // Send JSON response
|
| | | Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
| | | String json = gson.toJson(o);
|
| | | String json = JsonUtils.toJsonString(o);
|
| | | response.setCharacterEncoding(Constants.ENCODING);
|
| | | response.getWriter().append(json);
|
| | | }
|
| | | }
|