Search in sources :

Example 1 with OpenmrsCharacterEscapes

use of org.openmrs.OpenmrsCharacterEscapes in project openmrs-core by openmrs.

the class StartupFilter method toJSONString.

/**
 * Convenience method to convert the given object to a JSON string. Supports Maps, Lists,
 * Strings, Boolean, Double
 *
 * @param object object to convert to json
 * @return JSON string to be eval'd in javascript
 */
protected String toJSONString(Object object) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.getJsonFactory().setCharacterEscapes(new OpenmrsCharacterEscapes());
    try {
        return mapper.writeValueAsString(object);
    } catch (IOException e) {
        log.error("Failed to convert object to JSON");
        throw new APIException(e);
    }
}
Also used : APIException(org.openmrs.api.APIException) IOException(java.io.IOException) OpenmrsCharacterEscapes(org.openmrs.OpenmrsCharacterEscapes) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

IOException (java.io.IOException)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 OpenmrsCharacterEscapes (org.openmrs.OpenmrsCharacterEscapes)1 APIException (org.openmrs.api.APIException)1