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:org.jenkinsci.plugins.os_ci.utils.JsonBuilder.java

public static String createJson(Object jsonObj) {
    String jsonString;//w  w  w  .  j a v  a 2  s. c  o m
    ObjectMapper mapper = new ObjectMapper();
    try {
        mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
        jsonString = mapper.writeValueAsString(jsonObj);
        return jsonString;
    } catch (JsonGenerationException ex) {
        ex.printStackTrace();
    } catch (JsonMappingException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return null;
}

From source file:com.parworks.arviewer.utils.JsonMapper.java

public static ObjectMapper get() {
    if (mapper == null) {
        mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    }//from w w  w.  ja  v  a2 s.  co m
    return mapper;
}

From source file:io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString.java

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

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

/**
 * readValue//from ww w.j a  v a  2 s  .c  om
 *
 * @param <T>
 * @param json
 * @param clazz
 * @return
 */
public static <T> T readValue(String json, Class<T> clazz) {
    T result = null;
    try {
        ObjectMapper mapper = new ObjectMapper();
        result = mapper.readValue(json, clazz);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
    return result;
}

From source file:net.poemerchant.util.JsonUtils.java

public static String asString(Map<?, ?> map) throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper();
    String json = objectMapper.writeValueAsString(map);
    return json;/*  w w w.j  a  v a 2s.  co m*/
}

From source file:org.teavm.flavour.json.test.JSONRunner.java

public static <T> T deserialize(String json, Class<T> type) {
    try {/*  w  w  w . j  a  v a 2  s  .  c o m*/
        return new ObjectMapper().readValue(json, type);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.shampan.db.collections.fragment.status.ReferenceList.java

public static ReferenceList getReferenceList(String jsonContent) {
    ReferenceList refList = null;//from www. j ava  2 s .c om
    try {
        ObjectMapper mapper = new ObjectMapper();
        refList = mapper.readValue(jsonContent, ReferenceList.class);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return refList;
}

From source file:com.shampan.db.collections.fragment.status.Like.java

public static Like getStatusLike(String jsonContent) {
    Like likeInfo = null;/*w ww. j av a  2s . c om*/
    try {
        ObjectMapper mapper = new ObjectMapper();
        likeInfo = mapper.readValue(jsonContent, Like.class);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return likeInfo;
}

From source file:it.jugtorino.one.msvc.way.rabbit.reference.utils.JSONUtils.java

public static Map<String, Object> toMap(byte[] bytes) {
    ObjectMapper mapper = new ObjectMapper();

    TypeReference<Map<String, Object>> typeRef = new TypeReference<Map<String, Object>>() {
    };//from w ww . j  a  va  2s  .  c om

    try {
        return mapper.readValue(bytes, typeRef);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.axway.grapes.commons.utils.JsonUtils.java

/**
 * Serialize an object with Json/*from   ww  w  .  ja va 2 s  . com*/
 * @param obj Object
 * @return String
 * @throws IOException 
 */
public static String serialize(final Object obj) throws IOException {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS);
    return mapper.writeValueAsString(obj);

}