Example usage for com.fasterxml.jackson.databind ObjectMapper disable

List of usage examples for com.fasterxml.jackson.databind ObjectMapper disable

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind ObjectMapper disable.

Prototype

public ObjectMapper disable(SerializationFeature f) 

Source Link

Document

Method for enabling specified DeserializationConfig features.

Usage

From source file:storage.FileStorageInterface.java

private static ObjectMapper initMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    mapper.enable(SerializationFeature.CLOSE_CLOSEABLE);
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    return mapper;
}

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") {
        {//from w  ww.  j ava2s . c o  m
            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);
}

From source file:uk.ac.ebi.metabolights.webservice.client.MetabolightsWsClient.java

private <T> RestResponse<T> deserializeJSONString(String response, Class<T> valueType) {

    logger.debug("Parsing json response into MetaboLights model: " + response);

    // Parse response (json) into Study entity...

    // Add guava serialization for multimaps (Table.Fields is a multimap now).
    ObjectMapper mapper = new ObjectMapper();

    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

    try {//ww w.ja va2s .c  o  m

        JavaType type = mapper.getTypeFactory().constructParametricType(RestResponse.class, valueType);

        return mapper.readValue(response, type);

    } catch (IOException e) {

        logger.error("Can't parse ws response (json) back into " + valueType.getName() + ": " + e.getMessage());
        logger.debug("Response is: " + response);

    }

    return null;
}

From source file:uk.ac.ebi.metabolights.webservice.model.StudySerializationTest.java

@Test
public void testSerialization() throws IOException {

    Study study = getTestStudy();//from  w  w  w .j  av  a  2 s . c o m

    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

    String studyString = mapper.writeValueAsString(study);

    Assert.assertTrue("Test serialization of a title", studyString.contains("\"title\":\"title\""));

    // Test serialization of fields
    Assert.assertTrue("Test serialization of a fields", studyString.contains("\"header\":\"Field1\""));

    // Test serialization of users
    Assert.assertTrue("Test serialization of a users", studyString.contains("\"users\":[{"));

    // Test serialization of users, listofallstatus not serialized
    Assert.assertFalse("listofstatus is being serialized!", studyString.contains("listOfAllStatus"));

    // Test deserialisation now
    Study deserializedStudy = mapper.readValue(studyString, Study.class);

    Assert.assertTrue("Public release date is not properly kept during serialization and parsing.", DateUtils
            .isSameDay(study.getStudyPublicReleaseDate(), deserializedStudy.getStudyPublicReleaseDate()));

}