Example usage for com.fasterxml.jackson.datatype.jsr310 JavaTimeModule JavaTimeModule

List of usage examples for com.fasterxml.jackson.datatype.jsr310 JavaTimeModule JavaTimeModule

Introduction

In this page you can find the example usage for com.fasterxml.jackson.datatype.jsr310 JavaTimeModule JavaTimeModule.

Prototype

public JavaTimeModule() 

Source Link

Usage

From source file:keywhiz.KeywhizService.java

/**
 * Customizes ObjectMapper for common settings.
 *
 * @param objectMapper to be customized//w w  w . j  a v a 2s.  c om
 * @return customized input factory
 */
public static ObjectMapper customizeObjectMapper(ObjectMapper objectMapper) {
    objectMapper.registerModules(new Jdk8Module());
    objectMapper.registerModules(new JavaTimeModule());
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    return objectMapper;
}

From source file:com.muk.services.configuration.ServiceConfig.java

/**
 * @return A json object mapper used in all muk interactions.
 */// w ww.j ava 2s  .  com
@Bean(name = { "jsonObjectMapper" })
public ObjectMapper jsonObjectMapper() {
    final ObjectMapper mapper = new ObjectMapper();

    mapper.registerModule(new PairModule());
    mapper.registerModule(new JavaTimeModule());
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    return mapper;
}

From source file:alfio.config.MvcConfiguration.java

@Bean
public ObjectMapper objectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JavaTimeModule());
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    return mapper;
}

From source file:com.orange.ngsi2.client.Ngsi2Client.java

/**
 * Inject an ObjectMapper supporting Java8 and JavaTime module by default
 *//*from  ww w .  j a v  a2 s .  c o  m*/
protected void injectJava8ObjectMapper() {
    MappingJackson2HttpMessageConverter converter = getMappingJackson2HttpMessageConverter();
    if (converter != null) {
        converter.getObjectMapper().registerModule(new Jdk8Module()).registerModule(new JavaTimeModule())
                .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    }
}

From source file:sg.ncl.MainController.java

@PostMapping("/update_experiment/{teamId}/{expId}")
public String updateExperimentFormSubmit(@ModelAttribute("edit_experiment") Experiment2 editExperiment,
        BindingResult bindingResult, @PathVariable String teamId, @PathVariable String expId,
        RedirectAttributes redirectAttributes) throws WebServiceRuntimeException {

    // check max duration for errors
    if (bindingResult.hasErrors() || !editExperiment.getMaxDuration().toString().matches("\\d+")) {
        redirectAttributes.addFlashAttribute(MESSAGE, MAX_DURATION_ERROR);
        return REDIRECT_UPDATE_EXPERIMENT + teamId + "/" + expId;
    }/*from  ww w  .jav a2 s  .c  o  m*/

    // get original experiment
    HttpEntity<String> request = createHttpEntityHeaderOnly();
    ResponseEntity response = restTemplate.exchange(properties.getExperiment(expId), HttpMethod.GET, request,
            String.class);
    Experiment2 experiment = extractExperiment(response.getBody().toString());

    experiment.setNsFileContent(editExperiment.getNsFileContent());
    experiment.setMaxDuration(editExperiment.getMaxDuration());

    objectMapper.registerModule(new JavaTimeModule());
    String jsonExperiment;
    try {
        jsonExperiment = objectMapper.writeValueAsString(experiment);
    } catch (JsonProcessingException e) {
        log.debug("update experiment convert to json error: {}", experiment);
        redirectAttributes.addFlashAttribute(MESSAGE, ERR_SERVER_OVERLOAD);
        return REDIRECT_UPDATE_EXPERIMENT + teamId + "/" + expId;
    }

    // identical endpoint as delete experiment but different HTTP method
    restTemplate.setErrorHandler(new MyResponseErrorHandler());
    request = createHttpEntityWithBody(jsonExperiment);
    ResponseEntity updateExperimentResponse;
    try {
        updateExperimentResponse = restTemplate.exchange(properties.getDeleteExperiment(teamId, expId),
                HttpMethod.PUT, request, String.class);
    } catch (Exception e) {
        log.warn("Error connecting to experiment service to update experiment", e.getMessage());
        redirectAttributes.addFlashAttribute(MESSAGE, ERR_SERVER_OVERLOAD);
        return REDIRECT_EXPERIMENTS;
    }

    String updateExperimentResponseBody = updateExperimentResponse.getBody().toString();

    try {
        if (RestUtil.isError(updateExperimentResponse.getStatusCode())) {
            MyErrorResource error = objectMapper.readValue(updateExperimentResponseBody, MyErrorResource.class);
            ExceptionState exceptionState = ExceptionState.parseExceptionState(error.getError());

            switch (exceptionState) {
            case NS_FILE_PARSE_EXCEPTION:
            case EXPERIMENT_MODIFY_EXCEPTION:
                log.warn("update experiment failed for Team: {}, Exp: {}", teamId, expId);
                redirectAttributes.addFlashAttribute(MESSAGE, "Error in parsing NS File");
                redirectAttributes.addFlashAttribute("exp_output", error.getMessage());
                break;
            case OBJECT_OPTIMISTIC_LOCKING_FAILURE_EXCEPTION:
                // do nothing
                log.info("update experiment database locking failure");
                break;
            default:
                // do nothing
                break;
            }
            return REDIRECT_UPDATE_EXPERIMENT + teamId + "/" + expId;
        } else {
            // everything ok
            log.info("update experiment success for Team:{}, Exp: {}", teamId, expId);
            redirectAttributes.addFlashAttribute(EXPERIMENT_MESSAGE,
                    getExperimentMessage(experiment.getName(), experiment.getTeamName())
                            + " has been modified. You may proceed to start the experiment.");
            return REDIRECT_EXPERIMENTS;
        }
    } catch (IOException e) {
        throw new WebServiceRuntimeException(e.getMessage());
    }
}

From source file:sg.ncl.MainController.java

protected ZonedDateTime getZonedDateTime(String zonedDateTimeJSON) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JavaTimeModule());
    return mapper.readValue(zonedDateTimeJSON, ZonedDateTime.class);
}

From source file:ubicrypt.core.Utils.java

public static void configureMapper(final ObjectMapper mapper) {
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.registerModule(new Jdk8Module());
    mapper.registerModule(new JavaTimeModule());
    mapper.registerModule(new SimpleModule("ubicrypt module") {
        {// w  w  w  .  j  a v a 2s  .  com
            addSerializer(new PGPKValueSerializer(PGPKValue.class));
            addDeserializer(PGPKValue.class, new PGPKValueDeserializer(PGPKValue.class));
            addSerializer(new PathSerializer(Path.class));
            addDeserializer(Path.class, new PathDeserializer(Path.class));
        }
    });
    mapper.registerModule(new AfterburnerModule());
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}