Search in sources :

Example 6 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project vind by RBMHTechnology.

the class SearchApplication method main.

public static void main(String[] args) throws JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    mapper.registerModule(new JavaTimeModule());
    try (SearchService searchService = new SearchService()) {
        // index
        searchService.index();
        // search
        SearchResult result = searchService.news("vind");
        System.out.println(mapper.writeValueAsString(result));
    }
}
Also used : JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) SearchService(com.rbmhtechnology.vind.demo.step4.service.SearchService) SearchResult(com.rbmhtechnology.vind.api.result.SearchResult) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project FuryViewer by TheDoctor-95.

the class TestUtil method convertObjectToJsonBytes.

/**
 * Convert an object to JSON byte array.
 *
 * @param object
 *            the object to convert
 * @return the JSON byte array
 * @throws IOException
 */
public static byte[] convertObjectToJsonBytes(Object object) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    JavaTimeModule module = new JavaTimeModule();
    mapper.registerModule(module);
    return mapper.writeValueAsBytes(object);
}
Also used : JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 8 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project cals-api by ca-cwds.

the class LoggingFilter method filter.

@Override
public void filter(ClientRequestContext requestContext) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JavaTimeModule());
    LOG.info(System.getProperty("line.separator") + "!!! Test Request" + System.getProperty("line.separator") + "!!! URL: {}" + System.getProperty("line.separator") + "!!! Method: {}" + System.getProperty("line.separator") + "!!! Body: {}", requestContext.getUri(), requestContext.getMethod(), mapper.writerWithDefaultPrettyPrinter().writeValueAsString(requestContext.getEntity()));
}
Also used : JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 9 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project litemall by linlinjava.

the class JacksonConfig method objectMapper.

@Bean
@Primary
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
    JavaTimeModule javaTimeModule = new JavaTimeModule();
    javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
    javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
    javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
    ObjectMapper objectMapper = builder.createXmlMapper(false).build();
    objectMapper.registerModule(javaTimeModule);
    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    return objectMapper;
}
Also used : LocalTimeSerializer(com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) LocalDateSerializer(com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer) LocalDateTimeSerializer(com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 10 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project credhub by cloudfoundry-incubator.

the class TimeModuleFactory method createTimeModule.

public static JavaTimeModule createTimeModule() {
    JavaTimeModule javaTimeModule = new JavaTimeModule();
    javaTimeModule.addSerializer(Instant.class, new JsonSerializer<Instant>() {

        @Override
        public void serialize(Instant value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
            gen.writeString(ZonedDateTime.ofInstant(value, ZoneId.of("UTC")).format(TIMESTAMP_FORMAT));
        }
    });
    return javaTimeModule;
}
Also used : JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) Instant(java.time.Instant) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException) SerializerProvider(com.fasterxml.jackson.databind.SerializerProvider)

Aggregations

JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)75 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)59 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)16 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)7 ParameterNamesModule (com.fasterxml.jackson.module.paramnames.ParameterNamesModule)7 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)6 Test (org.junit.Test)6 Bean (org.springframework.context.annotation.Bean)6 JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)5 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)4 Before (org.junit.Before)4 Primary (org.springframework.context.annotation.Primary)4 StdDateFormat (com.fasterxml.jackson.databind.util.StdDateFormat)3 LocalDateSerializer (com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer)3 LocalDateTimeSerializer (com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer)3 LocalTimeSerializer (com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer)3 IOException (java.io.IOException)3 MetricsModule (com.codahale.metrics.json.MetricsModule)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)2 Module (com.fasterxml.jackson.databind.Module)2