Search in sources :

Example 36 with DefaultPrettyPrinter

use of com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project azure-tools-for-java by Microsoft.

the class CustomerSurveyManager method saveSurveyStatus.

private void saveSurveyStatus() {
    final ObjectMapper mapper = new ObjectMapper();
    final ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter());
    final File file = getConfigurationFile();
    try {
        if (!file.exists()) {
            file.createNewFile();
        }
        writer.writeValue(file, customerSurveyConfiguration);
    } catch (final IOException e) {
    // swallow exceptions for survey
    }
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) IOException(java.io.IOException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 37 with DefaultPrettyPrinter

use of com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project qpp-conversion-tool by CMSgov.

the class JsonWrapper method getPrinter.

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

Example 38 with DefaultPrettyPrinter

use of com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project zipkin by openzipkin.

the class JsonUtil method createGenerator.

/**
 * Creates a new {@link JsonGenerator} with pretty-printing enabled forcing {@code '\n'}
 * between lines, as opposed to Jackson's default which uses the system line separator.
 */
public static JsonGenerator createGenerator(Writer writer) throws IOException {
    JsonGenerator generator = JSON_FACTORY.createGenerator(writer);
    DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter();
    prettyPrinter.indentArraysWith(TWOSPACES_LF_INDENTER);
    prettyPrinter.indentObjectsWith(TWOSPACES_LF_INDENTER);
    generator.setPrettyPrinter(prettyPrinter);
    return generator;
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator)

Example 39 with DefaultPrettyPrinter

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

the class JsonXContentGenerator method usePrettyPrint.

@Override
public final void usePrettyPrint() {
    generator.setPrettyPrinter(new DefaultPrettyPrinter().withObjectIndenter(INDENTER).withArrayIndenter(INDENTER));
    prettyPrint = true;
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter)

Example 40 with DefaultPrettyPrinter

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

the class BaseOpenApiResource method getOpenApi.

protected Response getOpenApi(HttpHeaders headers, ServletConfig config, Application app, UriInfo uriInfo, String type) throws Exception {
    String ctxId = getContextId(config);
    OpenApiContext ctx = new JaxrsOpenApiContextBuilder().servletConfig(config).application(app).resourcePackages(resourcePackages).configLocation(configLocation).openApiConfiguration(openApiConfiguration).ctxId(ctxId).buildContext(true);
    OpenAPI oas = ctx.read();
    boolean pretty = false;
    if (ctx.getOpenApiConfiguration() != null && Boolean.TRUE.equals(ctx.getOpenApiConfiguration().isPrettyPrint())) {
        pretty = true;
    }
    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, getQueryParams(uriInfo.getQueryParameters()), getCookies(headers), getHeaders(headers));
            } catch (Exception e) {
                LOGGER.error("failed to load filter", e);
            }
        }
    }
    if (oas == null) {
        return Response.status(404).build();
    }
    if (StringUtils.isNotBlank(type) && type.trim().equalsIgnoreCase("yaml")) {
        return Response.status(Response.Status.OK).entity(pretty ? ctx.getOutputYamlMapper().writer(new DefaultPrettyPrinter()).writeValueAsString(oas) : ctx.getOutputYamlMapper().writeValueAsString(oas)).type("application/yaml").build();
    } else {
        return Response.status(Response.Status.OK).entity(pretty ? ctx.getOutputJsonMapper().writer(new DefaultPrettyPrinter()).writeValueAsString(oas) : ctx.getOutputJsonMapper().writeValueAsString(oas)).type(MediaType.APPLICATION_JSON_TYPE).build();
    }
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) OpenAPISpecFilter(io.swagger.v3.core.filter.OpenAPISpecFilter) JaxrsOpenApiContextBuilder(io.swagger.v3.jaxrs2.integration.JaxrsOpenApiContextBuilder) OpenAPI(io.swagger.v3.oas.models.OpenAPI) SpecFilter(io.swagger.v3.core.filter.SpecFilter) OpenAPISpecFilter(io.swagger.v3.core.filter.OpenAPISpecFilter) OpenApiContext(io.swagger.v3.oas.integration.api.OpenApiContext)

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