use of com.fasterxml.jackson.databind.ObjectWriter in project grakn by graknlabs.
the class SystemController method getMetrics.
@GET
@Path("/metrics")
private String getMetrics(Request request, Response response) throws IOException {
response.header(CACHE_CONTROL, "must-revalidate,no-cache,no-store");
response.status(HttpServletResponse.SC_OK);
Optional<String> format = Optional.ofNullable(request.queryParams(FORMAT));
String dFormat = format.orElse(JSON);
switch(dFormat) {
case PROMETHEUS:
// Prometheus format for the metrics
response.type(PROMETHEUS_CONTENT_TYPE);
final Writer writer1 = new StringWriter();
TextFormat.write004(writer1, this.prometheusRegistry.metricFamilySamples());
return writer1.toString();
case JSON:
// Json/Dropwizard format
response.type(APPLICATION_JSON);
final ObjectWriter writer = mapper.writer();
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
writer.writeValue(output, this.metricRegistry);
return new String(output.toByteArray(), "UTF-8");
}
default:
throw GraknServerException.requestInvalidParameter(FORMAT, dFormat);
}
}
use of com.fasterxml.jackson.databind.ObjectWriter in project graphhopper by graphhopper.
the class GHBaseServlet method writeJson.
protected void writeJson(HttpServletRequest req, HttpServletResponse res, JsonNode json) throws IOException {
String type = getParam(req, "type", "json");
res.setCharacterEncoding("UTF-8");
final boolean indent = getBooleanParam(req, "debug", false) || getBooleanParam(req, "pretty", false);
ObjectWriter objectWriter = indent ? objectMapper.writer().with(SerializationFeature.INDENT_OUTPUT) : objectMapper.writer();
if ("jsonp".equals(type)) {
res.setContentType("application/javascript");
if (!jsonpAllowed) {
writeError(res, SC_BAD_REQUEST, "Server is not configured to allow jsonp!");
return;
}
String callbackName = getParam(req, "callback", null);
if (callbackName == null) {
writeError(res, SC_BAD_REQUEST, "No callback provided, necessary if type=jsonp");
return;
}
writeResponse(res, callbackName + "(" + objectWriter.writeValueAsString(json) + ")");
} else {
res.setContentType("application/json");
writeResponse(res, objectWriter.writeValueAsString(json));
}
}
use of com.fasterxml.jackson.databind.ObjectWriter in project cxf by apache.
the class Java2SwaggerMojo method generateSwaggerPayLoad.
private void generateSwaggerPayLoad() throws MojoExecutionException {
if (outputFile == null && project != null) {
// Put the json in target/generated/json
// put the yaml in target/generated/yaml
String name = null;
if (outputFileName != null) {
name = outputFileName;
} else if (resourceClasses.size() == 1) {
name = resourceClasses.iterator().next().getSimpleName();
} else {
name = "swagger";
}
outputFile = (project.getBuild().getDirectory() + "/generated/" + payload.toLowerCase() + "/" + name + "." + payload.toLowerCase()).replace("/", File.separator);
}
BufferedWriter writer = null;
try {
FileUtils.mkDir(new File(outputFile).getParentFile());
writer = new BufferedWriter(new FileWriter(outputFile));
if ("json".equals(this.payload)) {
ObjectWriter jsonWriter = mapper.writer(new DefaultPrettyPrinter());
writer.write(jsonWriter.writeValueAsString(swagger));
} else if ("yaml".equals(this.payload)) {
writer.write(Yaml.pretty().writeValueAsString(swagger));
}
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
// with the enclosing project
if (attachSwagger && outputFile != null) {
File jsonFile = new File(outputFile);
if (jsonFile.exists()) {
if (classifier != null) {
projectHelper.attachArtifact(project, payload.toLowerCase(), classifier, jsonFile);
} else {
projectHelper.attachArtifact(project, payload.toLowerCase(), jsonFile);
}
}
}
}
use of com.fasterxml.jackson.databind.ObjectWriter in project ORCID-Source by ORCID.
the class OpenIDController method getOpenIDDiscovery.
/**
* Expose the openid discovery information
*
* @param request
* @return
* @throws JsonProcessingException
*/
@CrossOrigin
@RequestMapping(value = "/.well-known/openid-configuration", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public String getOpenIDDiscovery(HttpServletRequest request) throws JsonProcessingException {
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
String json = ow.writeValueAsString(openIDConnectDiscoveryService.getConfig());
return json;
}
use of com.fasterxml.jackson.databind.ObjectWriter in project drill by axbaretto.
the class TestParsePhysicalPlan method parseSimplePlan.
@Test
public void parseSimplePlan() throws Exception {
DrillConfig c = DrillConfig.create();
ScanResult scanResult = ClassPathScanner.fromPrescan(c);
LogicalPlanPersistence lpp = new LogicalPlanPersistence(c, scanResult);
PhysicalPlanReader reader = new PhysicalPlanReader(c, scanResult, lpp, CoordinationProtos.DrillbitEndpoint.getDefaultInstance(), null);
ObjectReader r = lpp.getMapper().reader(PhysicalPlan.class);
ObjectWriter writer = lpp.getMapper().writer();
PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/physical_test1.json"), Charsets.UTF_8));
String unparse = plan.unparse(writer);
// System.out.println(unparse);
}
Aggregations