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.creditcloud.interestbearing.model.ConfigObjBase.java

public static String toJSON(Object obj) {
    ObjectMapper mapper = new ObjectMapper();
    String json;/*from  ww w. java  2s . co  m*/
    try {
        json = mapper.writeValueAsString(obj); //
        return json;
    } catch (JsonProcessingException ex) {
        log.error("{}?JSON?", obj, ex);
        return "{}";
    }
}

From source file:de.taimos.dvalin.jaxrs.MapperFactory.java

public static ObjectMapper createDefault() {
    ObjectMapper m = new ObjectMapper();
    m.registerModule(new JodaModule());
    m.registerModule(new GuavaModule());
    m.setSerializationInclusion(Include.NON_NULL);
    m.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    m.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    m.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
    m.enable(MapperFeature.AUTO_DETECT_GETTERS);
    return m;/*from ww  w  .  j a  v a  2s  .  co m*/
}

From source file:m.omarh.liferay.resources.importer.generator.util.JSONUtil.java

public static String beautify(String json) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    Object obj = mapper.readValue(json, Object.class);
    return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj);
}

From source file:org.obiba.mica.web.rest.TestUtil.java

/**
 * Convert an object to JSON byte array.
 *
 * @param object the object to convert/*from   w  w w  .ja v  a2s  . c om*/
 * @return the JSON byte array
 * @throws IOException
 */
public static byte[] convertObjectToJsonBytes(Object object) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JodaModule());
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    return mapper.writeValueAsBytes(object);
}

From source file:dk.dma.msiproxy.common.util.JsonUtils.java

/**
 * Parses the json data as an entity of the given class
 *
 * @param data the json data to parse//  www  . ja v a  2s  .  com
 * @param dataClass the class of the data
 * @return the parsed data
 */
public static <T> T fromJson(String data, Class<T> dataClass) throws IOException {
    ObjectMapper jsonMapper = new ObjectMapper();
    return jsonMapper.readValue(data, dataClass);
}

From source file:org.baswell.routes.JacksonBridge.java

static void sendJackson(Object response, HttpServletResponse servletResponse) throws IOException {
    new ObjectMapper().writeValue(servletResponse.getWriter(), response);
}

From source file:com.shampan.db.collections.fragment.user.Group.java

public static Group getGroup(String jsonContent) {
    Group groupInfo = null;//from w ww.  ja  va2 s . c om
    try {
        ObjectMapper mapper = new ObjectMapper();
        groupInfo = mapper.readValue(jsonContent, Group.class);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return groupInfo;
}

From source file:com.playonlinux.core.python.JsonCodec.java

public static Map loads(String json) throws IOException {
    return new ObjectMapper().readValue(json, Map.class);
}

From source file:com.mapr.data.sputnik.config.JSONConfigReader.java

public static <T> T readConfig(InputStream input, Class<T> targetClass) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    return mapper.readValue(input, targetClass);
}

From source file:id.zelory.tanipedia.util.Utils.java

public static ArrayList<Berita> getRandomBerita(Context context, String alamat) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayList<Berita> beritaArrayList = null;
    try {//from www  .j  a va 2  s . c o  m
        beritaArrayList = mapper.readValue(PrefUtils.ambilString(context, "berita"),
                mapper.getTypeFactory().constructCollectionType(ArrayList.class, Berita.class));
    } catch (IOException e) {
        e.printStackTrace();
    }

    for (int i = 0; i < 5; i++) {
        int x = randInt(0, beritaArrayList.size() - 1);
        if (beritaArrayList.get(x).getAlamat().equals(alamat)) {
            beritaArrayList.remove(x);
            i--;
        } else {
            beritaArrayList.set(i, beritaArrayList.get(x));
            beritaArrayList.remove(x);
        }
    }

    for (int i = 5; i < beritaArrayList.size(); i++)
        beritaArrayList.remove(i);

    return beritaArrayList;
}