Example usage for com.fasterxml.jackson.core.io JsonStringEncoder getInstance

List of usage examples for com.fasterxml.jackson.core.io JsonStringEncoder getInstance

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core.io JsonStringEncoder getInstance.

Prototype

public static JsonStringEncoder getInstance() 

Source Link

Document

Factory method for getting an instance; this is either recycled per-thread instance, or a newly constructed one.

Usage

From source file:org.jboss.pnc.environment.openshift.OpenshiftStartedEnvironment.java

/**
 * Return an escaped string of the JSON representation of the object
 *
 * By 'escaped', it means that strings like '"' are escaped to '\"'
 * @param object object to marshall/*from w ww  .  j  av a 2  s. com*/
 * @return Escaped Json String
 */
private String toEscapedJsonString(Object object) {
    ObjectMapper mapper = new ObjectMapper();
    JsonStringEncoder jsonStringEncoder = JsonStringEncoder.getInstance();
    try {
        return new String(jsonStringEncoder.quoteAsString(mapper.writeValueAsString(object)));
    } catch (JsonProcessingException e) {
        logger.error("Could not parse object: " + object, e);
        throw new RuntimeException(e);
    }
}