Search in sources :

Example 1 with DefaultPrettyPrinter

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

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 2 with DefaultPrettyPrinter

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

the class YamlLexicalProcessor method createJacksonGenerator.

public YAMLGenerator createJacksonGenerator(StringWriter out) throws SchemaException {
    try {
        MidpointYAMLFactory factory = new MidpointYAMLFactory();
        MidpointYAMLGenerator generator = (MidpointYAMLGenerator) factory.createGenerator(out);
        generator.setPrettyPrinter(new DefaultPrettyPrinter());
        generator.setCodec(configureMapperForSerialization());
        return generator;
    } catch (IOException ex) {
        throw new SchemaException("Schema error during serializing to JSON.", ex);
    }
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) MidpointYAMLGenerator(com.evolveum.midpoint.prism.lex.json.yaml.MidpointYAMLGenerator) MidpointYAMLFactory(com.evolveum.midpoint.prism.lex.json.yaml.MidpointYAMLFactory) IOException(java.io.IOException)

Example 3 with DefaultPrettyPrinter

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

the class TestJDKSerializability method testPrettyPrinter.

public void testPrettyPrinter() throws Exception {
    PrettyPrinter p = new DefaultPrettyPrinter();
    byte[] stuff = jdkSerialize(p);
    PrettyPrinter back = jdkDeserialize(stuff);
    // what should we test?
    assertNotNull(back);
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) PrettyPrinter(com.fasterxml.jackson.core.PrettyPrinter)

Example 4 with DefaultPrettyPrinter

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

the class JSONUtils method enableDisableJSONGeneratorFeature.

public static JsonGenerator enableDisableJSONGeneratorFeature(JsonGenerator generator) {
    generator.enable(Feature.ESCAPE_NON_ASCII);
    generator.disable(Feature.AUTO_CLOSE_TARGET);
    generator.setPrettyPrinter(new DefaultPrettyPrinter());
    return generator;
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter)

Example 5 with DefaultPrettyPrinter

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

the class JacksonSerializeUnitTest method whenCustomSerialize_thenCorrect.

@Test
public void whenCustomSerialize_thenCorrect() throws ParseException, IOException {
    final SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
    final ActorJackson rudyYoungblood = new ActorJackson("nm2199632", sdf.parse("21-09-1982"), Arrays.asList("Apocalypto", "Beatdown", "Wind Walkers"));
    final MovieWithNullValue movieWithNullValue = new MovieWithNullValue(null, "Mel Gibson", Arrays.asList(rudyYoungblood));
    final SimpleModule module = new SimpleModule();
    module.addSerializer(new ActorJacksonSerializer(ActorJackson.class));
    final ObjectMapper mapper = new ObjectMapper();
    final String jsonResult = mapper.registerModule(module).writer(new DefaultPrettyPrinter()).writeValueAsString(movieWithNullValue);
    final Object json = mapper.readValue("{\"actors\":[{\"imdbId\":\"nm2199632\",\"dateOfBirth\":\"21-09-1982\",\"N° Film: \":3,\"filmography\":\"Apocalypto-Beatdown-Wind Walkers\"}],\"imdbID\":null}", Object.class);
    final String expectedOutput = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT).writeValueAsString(json);
    Assert.assertEquals(jsonResult, expectedOutput);
}
Also used : ActorJackson(com.baeldung.jackson.entities.ActorJackson) DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) MovieWithNullValue(com.baeldung.jackson.entities.MovieWithNullValue) SimpleDateFormat(java.text.SimpleDateFormat) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

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