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.github.arven.sleuth.commands.json.java

public static Object invoke(Interpreter env, CallStack callstack, String s) throws Exception {
    ObjectMapper m = new ObjectMapper();
    return m.readValue(s, Object.class);
}

From source file:com.mac.holdempoker.socket.JsonConverter.java

public static String toJsonString(Object obj) throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();

    //configure Object mapper for pretty print
    objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);

    //writing to console, can write to any output stream such as file
    StringWriter jsonString = new StringWriter();
    objectMapper.writeValue(jsonString, obj);
    return jsonString.toString();
}

From source file:cn.dataprocess.cfzk.JsonUtil.java

public static String toJsonString(Object sourceObject) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    String ret = mapper.writeValueAsString(sourceObject);
    mapper = null;/* ww w . jav a  2  s .c  o  m*/
    return ret;
}

From source file:edu.ub.ir.oof1.Util.JSONUtil.java

public static String modelsToJsonArray(List<AbstractModel> _models) {
    String out = "";

    try {/*  w  ww .  ja  v  a 2 s.  co m*/
        ObjectMapper mapper = new ObjectMapper();
        out = mapper.writeValueAsString(_models);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return out;
}

From source file:persistence.ContactPersistence.java

public static void createContact(Contact contact) throws IOException {

    ObjectMapper mapper = new ObjectMapper();

    String data = mapper.writeValueAsString(contact);

    JestConfig.indexData(typeName, data);
}

From source file:com.github.arven.sleuth.commands.json.java

public static Object json(String s) throws Exception {
    ObjectMapper m = new ObjectMapper();
    return m.readValue(s, Object.class);
}

From source file:com.mafia.server.util.JacksonUtils.java

public static String objectToString(Object t) {
    try {/*from www  .  j  a v a 2s.c  o m*/
        ObjectMapper objectMapper = new ObjectMapper();
        return objectMapper.writeValueAsString(t);
    } catch (JsonProcessingException ex) {
        Logger.getLogger(JacksonUtils.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:com.lucas.analytics.controller.ml.SearchController.java

public static Search getSearch(String query) throws IOException {
    ObjectMapper mapper = new ObjectMapper();

    String noWhitespace = query.replace(" ", "+");

    String targetUrl = baseUrl + "?q=" + StringEscapeUtils.escapeHtml4(noWhitespace) + "&limit=10";

    System.out.println("targetUrl: " + targetUrl);

    return mapper.readValue(Request.Get(targetUrl).execute().returnContent().asString(), Search.class);
}

From source file:su90.etl.utils.DeviceTypeParser.java

public static void initializer(String path) {

    hashmapper = new HashMap<>();

    ObjectMapper mapper = new ObjectMapper();
    try {/*from  www .ja  v  a 2  s.  c  o m*/

        Object[][] objs = mapper.readValue(new FileReader(path), Object[][].class);

        for (Object[] subobjs : objs) {
            hashmapper.put((Integer) subobjs[0], (String) subobjs[1]);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:xyz.monotalk.social.mixcloud.internal.JsonUtils.java

/**
 * toMap/*from  w w  w.j  av a  2 s  .  c  om*/
 *
 * @param obj
 * @return
 */
public static Map<String, Object> toMap(Object obj) {
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> objectAsMap = mapper.convertValue(obj, Map.class);
    return objectAsMap;
}