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:org.axway.grapes.commons.utils.JsonUtils.java

/**
 * Un-serialize a Json into Organization
 * @param organization String/*from   ww  w .  j  a  v a2s.  c  om*/
 * @return Organization
 * @throws IOException
 */
public static Organization unserializeOrganization(final String organization) throws IOException {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS);
    return mapper.readValue(organization, Organization.class);
}

From source file:org.axway.grapes.commons.utils.JsonUtils.java

/**
 * Un-serialize a Json into Module//from w  w  w . j a  v  a  2 s . c o m
 * @param module String
 * @return Module
 * @throws IOException
 */
public static Module unserializeModule(final String module) throws IOException {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS);
    return mapper.readValue(module, Module.class);
}

From source file:org.axway.grapes.commons.utils.JsonUtils.java

/**
 * Un-serialize a report with Json// w  ww .  j a va 2 s. c  om
 * @param artifact String
 * @return Artifact
 * @throws IOException 
 */
public static Artifact unserializeArtifact(final String artifact) throws IOException {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS);
    return mapper.readValue(artifact, Artifact.class);
}

From source file:org.axway.grapes.commons.utils.JsonUtils.java

/**
 * Un-serialize a report with Json/*from  www  .  j  a v  a  2 s . c  o  m*/
 * @param license String
 * @return License
 * @throws IOException 
 */
public static License unserializeLicense(final String license) throws IOException {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS);
    return mapper.readValue(license, License.class);
}

From source file:org.axway.grapes.commons.utils.JsonUtils.java

/**
 * Serialize an object with Json/*from  w w  w . j ava2 s  .c o  m*/
 * @param obj Object
 * @return String
 * @throws IOException 
 */
public static String serialize(final Object obj) throws IOException {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS);
    return mapper.writeValueAsString(obj);

}

From source file:org.axway.grapes.commons.utils.JsonUtils.java

/**
 * Un-serialize a Json into BuildInfo/*w ww. j a v  a2s  . c  o  m*/
 * @param buildInfo String
 * @return Map<String,String>
 * @throws IOException
 */
public static Map<String, String> unserializeBuildInfo(final String buildInfo) throws IOException {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS);
    return mapper.readValue(buildInfo, new TypeReference<Map<String, Object>>() {
    });
}

From source file:org.hawkular.rx.cdi.JacksonConfig.java

public static void initializeObjectMapper(ObjectMapper mapper) {
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    mapper.disable(SerializationFeature.WRITE_NULL_MAP_VALUES);
    mapper.disable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    mapper.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
    mapper.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    InventoryJacksonConfig.configure(mapper);
    //need to reconfigure for path serialization
    mapper.addMixIn(CanonicalPath.class, PathSerializationMixin.class);
    mapper.addMixIn(RelativePath.class, PathSerializationMixin.class);
}

From source file:org.bigloupe.web.monitor.util.JSONUtil.java

public static String formatJson(Object object) throws IOException {
    ObjectMapper om = new ObjectMapper();
    om.enable(SerializationFeature.INDENT_OUTPUT);
    om.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    return om.writeValueAsString(object);
}

From source file:org.bigloupe.web.monitor.util.JSONUtil.java

/**
 * Writes object to the writer as JSON using Jackson and adds a new-line
 * before flushing.//from  w w w  . j  a v  a 2s  . c om
 * 
 * @param writer
 *            the writer to write the JSON to
 * @param object
 *            the object to write as JSON
 * @throws IOException
 *             if the object can't be serialized as JSON or written to the
 *             writer
 */
public static void writeJson(Writer writer, Object object) throws IOException {
    ObjectMapper om = new ObjectMapper();
    om.enable(SerializationFeature.INDENT_OUTPUT);
    om.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);

    writer.write(om.writeValueAsString(object));
    writer.write("\n");
    writer.flush();
}

From source file:com.wrmsr.kleist.util.Json.java

public static ObjectMapper newObjectMapper() {
    // TODO: io.airlift.json
    ObjectMapper objectMapper = new ObjectMapper();

    // ignore unknown fields (for backwards compatibility)
    objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

    // use ISO dates
    objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);

    // skip fields that are null instead of writing an explicit json null value
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    // disable auto detection of json properties... all properties must be explicit
    objectMapper.disable(MapperFeature.AUTO_DETECT_CREATORS);
    objectMapper.disable(MapperFeature.AUTO_DETECT_FIELDS);
    objectMapper.disable(MapperFeature.AUTO_DETECT_SETTERS);
    objectMapper.disable(MapperFeature.AUTO_DETECT_GETTERS);
    objectMapper.disable(MapperFeature.AUTO_DETECT_IS_GETTERS);
    objectMapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS);
    objectMapper.disable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS);
    objectMapper.disable(MapperFeature.INFER_PROPERTY_MUTATORS);
    objectMapper.disable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS);

    objectMapper.registerModules(new Jdk8Module(), new JSR310Module(), new GuavaModule());

    return objectMapper;
}