Search in sources :

Example 11 with DefaultPrettyPrinter

use of com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project solr-document-store by DBCDK.

the class SolrWorkerIT method testAddDocument.

@Test
public // @Ignore
void testAddDocument() throws Exception {
    System.out.println("testAddDocument");
    repository.ingestObject(FileUtils.readFileToString(new File(UNIT_FILE)));
    repository.ingestObject(FileUtils.readFileToString(new File(REAL_PID_FILE)));
    repository.commit();
    // Put pid-message on pidQueue
    MapMessage mm = session.createMapMessage();
    mm.setString("pid", PID);
    pidProducer.send(mm);
    ArrayNode responses = fetch();
    System.out.println("responses:" + JSON_OBJECT_MAPPER.writer(new DefaultPrettyPrinter()).writeValueAsString(responses));
    contentTest(responses, "testAddDocument.yaml");
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) MapMessage(javax.jms.MapMessage) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) File(java.io.File) Test(org.junit.Test)

Example 12 with DefaultPrettyPrinter

use of com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project spring-framework by spring-projects.

the class Jackson2JsonEncoder method initSsePrettyPrinter.

private static PrettyPrinter initSsePrettyPrinter() {
    DefaultPrettyPrinter printer = new DefaultPrettyPrinter();
    printer.indentObjectsWith(new DefaultIndenter("  ", "\ndata:"));
    return printer;
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) DefaultIndenter(com.fasterxml.jackson.core.util.DefaultIndenter)

Example 13 with DefaultPrettyPrinter

use of com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project flink by apache.

the class RestAPIStabilityTest method writeSnapshot.

private static void writeSnapshot(final String versionedSnapshotFileName, final RestAPISnapshot snapshot) throws IOException {
    OBJECT_MAPPER.writer(new DefaultPrettyPrinter().withObjectIndenter(new DefaultIndenter().withLinefeed("\n"))).writeValue(new File("src/test/resources/" + versionedSnapshotFileName), snapshot);
    System.out.println("REST API snapshot " + versionedSnapshotFileName + " was updated, please remember to commit the snapshot.");
}
Also used : DefaultPrettyPrinter(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.util.DefaultPrettyPrinter) DefaultIndenter(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.util.DefaultIndenter) File(java.io.File)

Example 14 with DefaultPrettyPrinter

use of com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project rest.li by linkedin.

the class IndentedPdlBuilder method getPrettyPrinter.

private PrettyPrinter getPrettyPrinter() {
    DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter();
    prettyPrinter.indentObjectsWith(new DefaultIndenter(getIndentSpaces(1), DefaultIndenter.SYS_LF + getIndentSpaces(_indentDepth)));
    return prettyPrinter;
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) DefaultIndenter(com.fasterxml.jackson.core.util.DefaultIndenter)

Example 15 with DefaultPrettyPrinter

use of com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project swagger-core by swagger-api.

the class OpenApiServlet method doGet.

// TODO move to own servlet non jaxrs project and reference from there
// TODO cleanup and errors
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String ctxId = getContextIdFromServletConfig(getServletConfig());
    OpenApiContext ctx = OpenApiContextLocator.getInstance().getOpenApiContext(ctxId);
    OpenAPI oas = ctx.read();
    if (oas != null) {
        if (ctx.getOpenApiConfiguration() != null && ctx.getOpenApiConfiguration().getFilterClass() != null) {
            try {
                OpenAPISpecFilter filterImpl = (OpenAPISpecFilter) Class.forName(ctx.getOpenApiConfiguration().getFilterClass()).newInstance();
                SpecFilter f = new SpecFilter();
                oas = f.filter(oas, filterImpl, ServletUtils.getQueryParams(req.getParameterMap()), ServletUtils.getCookies(req.getCookies()), ServletUtils.getHeaders(req));
            } catch (Exception e) {
                LOGGER.error("failed to load filter", e);
            }
        }
    }
    String type = "json";
    String acceptHeader = req.getHeader(ACCEPT_HEADER);
    if (!StringUtils.isBlank(acceptHeader) && acceptHeader.toLowerCase().contains(APPLICATION_YAML)) {
        type = "yaml";
    } else {
        // check URL:
        if (req.getRequestURL().toString().toLowerCase().endsWith("yaml")) {
            type = "yaml";
        }
    }
    boolean pretty = false;
    if (ctx.getOpenApiConfiguration() != null && Boolean.TRUE.equals(ctx.getOpenApiConfiguration().isPrettyPrint())) {
        pretty = true;
    }
    resp.setStatus(200);
    if (type.equalsIgnoreCase("yaml")) {
        resp.setContentType(APPLICATION_YAML);
        try (PrintWriter pw = resp.getWriter()) {
            pw.write(pretty ? ctx.getOutputYamlMapper().writer(new DefaultPrettyPrinter()).writeValueAsString(oas) : ctx.getOutputYamlMapper().writeValueAsString(oas));
        }
    } else {
        resp.setContentType(APPLICATION_JSON);
        try (PrintWriter pw = resp.getWriter()) {
            pw.write(pretty ? ctx.getOutputJsonMapper().writer(new DefaultPrettyPrinter()).writeValueAsString(oas) : ctx.getOutputJsonMapper().writeValueAsString(oas));
        }
    }
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) OpenAPISpecFilter(io.swagger.v3.core.filter.OpenAPISpecFilter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) SpecFilter(io.swagger.v3.core.filter.SpecFilter) OpenAPISpecFilter(io.swagger.v3.core.filter.OpenAPISpecFilter) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) OpenApiConfigurationException(io.swagger.v3.oas.integration.OpenApiConfigurationException) OpenApiContext(io.swagger.v3.oas.integration.api.OpenApiContext) PrintWriter(java.io.PrintWriter)

Aggregations

DefaultPrettyPrinter (com.fasterxml.jackson.core.util.DefaultPrettyPrinter)42 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 IOException (java.io.IOException)9 File (java.io.File)7 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)6 DefaultIndenter (com.fasterxml.jackson.core.util.DefaultIndenter)6 OpenApiContext (io.swagger.v3.oas.integration.api.OpenApiContext)6 OpenAPI (io.swagger.v3.oas.models.OpenAPI)6 SwaggerConfiguration (io.swagger.v3.oas.integration.SwaggerConfiguration)4 PrettyPrinter (com.fasterxml.jackson.core.PrettyPrinter)3 JsonFactory (com.fasterxml.jackson.core.json.JsonFactory)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)3 OpenAPISpecFilter (io.swagger.v3.core.filter.OpenAPISpecFilter)3 SpecFilter (io.swagger.v3.core.filter.SpecFilter)3 OpenApiConfigurationException (io.swagger.v3.oas.integration.OpenApiConfigurationException)3 BufferedWriter (java.io.BufferedWriter)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3