use of com.fasterxml.jackson.databind.util.JSONPObject in project metrics by dropwizard.
the class MetricsServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType(CONTENT_TYPE);
if (allowedOrigin != null) {
resp.setHeader("Access-Control-Allow-Origin", allowedOrigin);
}
resp.setHeader("Cache-Control", "must-revalidate,no-cache,no-store");
resp.setStatus(HttpServletResponse.SC_OK);
final OutputStream output = resp.getOutputStream();
try {
if (jsonpParamName != null && req.getParameter(jsonpParamName) != null) {
getWriter(req).writeValue(output, new JSONPObject(req.getParameter(jsonpParamName), registry));
} else {
getWriter(req).writeValue(output, registry);
}
} finally {
output.close();
}
}
use of com.fasterxml.jackson.databind.util.JSONPObject in project ninja by ninjaframework.
the class TemplateEngineJsonP method invoke.
@Override
public void invoke(Context context, Result result) {
ResponseStreams responseStreams = context.finalizeHeaders(result);
String callback = getCallbackName(context);
try (OutputStream outputStream = responseStreams.getOutputStream()) {
objectMapper.writeValue(outputStream, new JSONPObject(callback, result.getRenderable()));
} catch (IOException e) {
logger.error("Error while rendering jsonp.", e);
}
}
use of com.fasterxml.jackson.databind.util.JSONPObject in project jackson-databind by FasterXML.
the class TestJSONP method testWithType.
/**
* Test to ensure that it is possible to force a static type for wrapped
* value.
*/
public void testWithType() throws Exception {
Object ob = new Impl("abc", "def");
JavaType type = MAPPER.constructType(Base.class);
assertEquals("do({\"a\":\"abc\"})", MAPPER.writeValueAsString(new JSONPObject("do", ob, type)));
}
Aggregations