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:com.centurylink.cloud.sdk.core.ToStringMixin.java

default String toReadableString() {
    try {// www.  ja  va 2  s .  co  m
        return new ObjectMapper().enableDefaultTypingAsProperty(NON_FINAL, "class").writeValueAsString(this);
    } catch (JsonProcessingException ex) {
        throw new ClcException(ex);
    }
}

From source file:org.neo4j.cineasts.movieimport.MovieDbApiClient.java

public MovieDbApiClient(String apiKey) {
    this.apiKey = apiKey;
    mapper = new ObjectMapper();
}

From source file:com.ubershy.streamsis.project.ProjectSerializator.java

/**
 * Serialize {@link CuteProject} to string.
 *
 * @param project/* w w w .j a  v  a 2s . c o  m*/
 *            the {@link CuteProject} to serialize
 * @return the string in JSON format
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static String serializeToString(CuteProject project) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    String serialized = null;
    try {
        serialized = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(project);
    } catch (JsonGenerationException e) {
        logger.error("CuteProject serializing to string fail: JsonGeneration error");
        e.printStackTrace();
        throw e;
    } catch (JsonMappingException e) {
        logger.error("CuteProject serializing to string fail: Mapping error");
        e.printStackTrace();
        throw e;
    } catch (IOException e) {
        logger.error("CuteProject serializing to string fail: IO error");
        throw e;
    }
    logger.debug("CuteProject serializing to string success");
    return serialized;
}

From source file:com.jyzn.wifi.validate.other.JacksonTest.java

@Test
public void writeMapJSON() {

    ObjectMapper om = new ObjectMapper();
    try {/* www  .j  a  v  a  2 s.  com*/

        JsonGenerator jg = om.getFactory().createGenerator(System.out, JsonEncoding.UTF8);

        ImmutableMap<String, String> map = ImmutableMap.of("status", "sucess", "validateCode", "123456");

        jg.writeObject(map);
        //?om.writeValue/writeValueJsonGenerator.writeObject?
        om.writeValue(System.out, map);
        // om.writeValueAsString(map);

    } catch (IOException e) {
    }
}

From source file:org.deeplearning4j.arbiter.optimize.ui.misc.ObjectMapperProvider.java

@Override
public ObjectMapper getContext(Class<?> type) {
    final ObjectMapper result = new ObjectMapper();
    result.registerModule(module());/*from  w w w .  j  av  a  2 s . c o  m*/
    return result;
}

From source file:io.fabric8.mq.controller.coordination.ReplicationControllerTest.java

@Test
public void testCreateReplicationController() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    /*/*  w  w w.j a  v  a 2s.  com*/
    String basedir = System.getProperty("basedir", "apps/fabric8-mq-controller");
    String fileName = basedir + "/src/main/resources/replication-template.json";
    */

    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    URL url = classLoader.getResource("META-INF/replicator-template.json");

    ReplicationController result = mapper.reader(ReplicationController.class).readValue(url);

    Assert.assertNotNull(result);
}

From source file:utils.JsonConfiguration.java

private static ObjectMapper createDefaultMapper() {

    ObjectMapper result = new ObjectMapper();
    result.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    return result;
}

From source file:com.teradata.presto.yarn.test.slider.SliderStatus.java

public SliderStatus(String statusJson) {
    ObjectMapper objectMapper = new ObjectMapper();
    try {//from   ww  w  . j  a  v a 2s.c  o  m
        this.status = objectMapper.readTree(statusJson);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:se.carlengstrom.internetonastick.samples.irc.IrcBot.java

public IrcBot(final IrcConfig config) {
    this.config = config;
    this.mapper = new ObjectMapper().registerModule(new AutoMatterModule());
    this.client = new OkHttpClient();
}

From source file:org.fastj.fit.tool.JSONHelper.java

public static Map<String, Object> getJson(String content) {
    if (content == null || (content = content.trim()).isEmpty()) {
        return new HashMap<String, Object>();
    }//w w w  .  j a  v  a2  s.  co  m
    Map<String, Object> jo = null;
    if (content.matches("^(\\{|\\[)[\\S\\s]*(\\}|\\])$")) {
        ObjectMapper mapper = new ObjectMapper();
        try {
            if (content.startsWith("{")) {
                jo = mapper.readValue(content, new JsonType<Map<String, Object>>());
            } else {
                Object l = mapper.readValue(content, new JsonType<List<Object>>());
                jo = new HashMap<>();
                jo.put("list", l);
            }
        } catch (Throwable e) {
        }
    }

    //xml
    if (jo == null) {
        if (content.matches("^<[\\S\\s]*>$")) {
            Document doc = JdomHelper.build(content);
            if (doc != null) {
                jo = xml2Json(doc);
            }
        }

        if (jo == null) {
            jo = new HashMap<String, Object>();
            jo.put("content", content);
        }
    }

    return jo;
}