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

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

Introduction

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

Prototype

public ObjectMapper enableDefaultTyping(DefaultTyping dti) 

Source Link

Document

Convenience method that is equivalent to calling
 enableObjectTyping(dti, JsonTypeInfo.As.WRAPPER_ARRAY); 

Usage

From source file:com.mylife.hbase.mapper.serialization.json.JsonSerializer.java

private static ObjectMapper GET_OBJECT_MAPPER() {
    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    return objectMapper;
}

From source file:com.amazonaws.services.simpleworkflow.flow.common.WorkflowExecutionUtils.java

public static String printDetails(String details) {
    Throwable failure = null;//from  w  w w  .  ja v a 2s .com
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.enableDefaultTyping(DefaultTyping.NON_FINAL);

        failure = mapper.readValue(details, Throwable.class);
    } catch (Exception e) {
        // eat up any data converter exceptions
    }

    if (failure != null) {
        StringBuilder builder = new StringBuilder();

        // Also print callstack
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        failure.printStackTrace(pw);

        builder.append(sw.toString());

        details = builder.toString();
    }

    return details;
}

From source file:com.thesett.util.hibernate.JsonUserType.java

/**
 * Transforms a JSON string into an object.
 *
 * @param  content The JSON string to parse.
 *
 * @return The JSON as an object.//from w  w  w .  j  a v  a2s. c o m
 */
Object convertJsonToObject(String content) {
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);

        return mapper.readValue(content, Object.class);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}

From source file:com.thesett.util.hibernate.JsonUserType.java

/**
 * Transforms an object into JSON.//ww w . jav a  2s .c o m
 *
 * @param  object The object to convert to JSON.
 *
 * @return The object as a JSON string.
 */
String convertObjectToJson(Object object) {
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

        return mapper.writeValueAsString(object);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}

From source file:org.pentaho.platform.plugin.action.ActionParams.java

/**
 * Convenience method for serializing a params map.
 *
 * @param params the parameter map./*from www. j a  va2  s  . c  om*/
 * @return the serialized representation of the map.
 * @throws JsonProcessingException if anything goes wrong.
 */
private static String serializeParams(final Map<String, Serializable> params) throws JsonProcessingException {
    final ObjectMapper mapper = new ObjectMapper();
    // this mapper configuration is required to enable de-serialization.
    // the mapper object will inject type info into the json for this purpose.
    //
    mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    return mapper.writeValueAsString(params);
}

From source file:org.pentaho.platform.plugin.action.ActionParams.java

/**
 * Convenience method for de-serialize a params map that was serialize with serializeParams() method.
 *
 * @param serializedParams the parameter map.
 * @return the serialized representation of the map.
 * @throws JsonProcessingException if anything goes worng.
 *///from w w w . j  a va2 s  .com
private static Map<String, Serializable> deserializeParams(final String serializedParams) throws IOException {
    final ObjectMapper mapper = new ObjectMapper();

    mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    return mapper.readValue(serializedParams, HashMap.class);
}