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

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

Introduction

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

Prototype

public ObjectMapper() 

Source Link

Document

Default constructor, which will construct the default JsonFactory as necessary, use SerializerProvider as its SerializerProvider , and BeanSerializerFactory as its SerializerFactory .

Usage

From source file:de.javagl.jgltf.model.io.JsonUtils.java

/**
 * Creates a formatted (pretty-printed, indented) representation of
 * the given JSON string. The details of the formatting are not 
 * specified. If there is any error during this process, then a 
 * warning will be printed and the given string will be returned.
 * /*from  w  ww .  ja v  a 2s .  co m*/
 * @param jsonString The input JSON string
 * @return The formatted JSON string
 */
public static String format(String jsonString) {
    ObjectMapper mapper = new ObjectMapper();
    try {
        Object object = mapper.readValue(jsonString, Object.class);
        String formattedJsonString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(object);
        return formattedJsonString;
    } catch (IOException e) {
        logger.warning(e.getMessage());
        return jsonString;
    }
}

From source file:com.flipkart.zjsonpatch.ApiTest.java

@Test(expected = InvalidJsonPatchException.class)
public void applyingNonArrayPatchShouldThrowAnException() throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode invalid = objectMapper.readTree("{\"not\": \"a patch\"}");
    JsonNode to = objectMapper.readTree("{\"a\":1}");
    JsonPatch.apply(invalid, to);/*from   ww w.  j av  a2 s  .co  m*/
}

From source file:com.linecorp.bot.model.message.imagemap.MessageImagemapActionTest.java

@Test
public void getText() throws Exception {
    MessageImagemapAction imageMapAction = new MessageImagemapAction("hoge", new ImagemapArea(1, 2, 3, 4));

    ObjectMapper objectMapper = new ObjectMapper();
    String s = objectMapper.writeValueAsString(imageMapAction);
    assertThat(s).contains("\"type\":\"message\"");
}