Example usage for com.fasterxml.jackson.databind.type TypeFactory defaultInstance

List of usage examples for com.fasterxml.jackson.databind.type TypeFactory defaultInstance

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.type TypeFactory defaultInstance.

Prototype

public static TypeFactory defaultInstance() 

Source Link

Usage

From source file:org.camunda.spin.impl.json.jackson.format.DefaultJsonJacksonTypeDetector.java

public String detectType(Object object) {
    Class<?> type = object.getClass();
    return TypeFactory.defaultInstance().constructType(type).toCanonical();
}

From source file:com.thoughtworks.studios.journey.utils.JSONUtils.java

public static <T> List<T> jsonToListOfT(String json, Class<Map> claz) throws IOException {
    return MAPPER.readValue(json, TypeFactory.defaultInstance().constructCollectionType(List.class, claz));
}

From source file:edu.sjsu.cohort6.esp.common.CommonUtils.java

/**
 * Converts a JSON array of objects to List of Java Object types.
 * For example, convert a JSON array of students to List<Student>.
 *
 * @param jsonArrayStr/*from w  w  w .  j  a v a  2 s.c o m*/
 * @param clazz
 * @param <T>
 * @return
 * @throws java.io.IOException
 */
public static <T> List<T> convertJsonArrayToList(String jsonArrayStr, Class<T> clazz)
        throws java.io.IOException {
    ObjectMapper mapper = new ObjectMapper();
    //jsonArrayStr = removeIdField(jsonArrayStr);
    return mapper.readValue(jsonArrayStr,
            TypeFactory.defaultInstance().constructCollectionType(List.class, clazz));
}

From source file:com.github.jasonruckman.sidney.core.type.Types.java

public static TypeBindings binding(Class type, Class... generics) {
    JavaType javaType = TypeFactory.defaultInstance().constructParametricType(type, generics);
    return new TypeBindings(TypeFactory.defaultInstance(), javaType);
}

From source file:net.floodlightcontroller.queuepusher.QueuePusherSwitchMapper.java

/**
 * Given the switch DPID it returns its ip and port by querying floodlight
 * //from www  .  j a v  a2 s. co  m
 * @param dpid Switch dpid
 * @return 0: ip 1: port
 */

private static Object[] getCURLMatch(String dpid) {

    Object[] rsp = eval("curl -s http://127.0.0.1:8080/wm/core/controller/switches/json");
    ObjectMapper mapper = new ObjectMapper();

    List<Map<String, Object>> args = null;
    try {
        logger.info("JSON received from CURL: " + rsp[1]);
        args = mapper.readValue((String) rsp[1],
                TypeFactory.defaultInstance().constructCollectionType(List.class, Map.class));
    } catch (IOException e) {
        logger.warn("Error parsing JSON arguments", e);
    }

    String ip = null;
    int port = 0;
    for (Map<String, Object> entry : args) {
        if (((String) entry.get("dpid")).equals(dpid)) {
            String temp = ((String) entry.get("inetAddress")).substring(1);
            ip = temp.substring(0, temp.indexOf(":"));
            port = Integer.parseInt(temp.substring(temp.indexOf(":") + 1));
            break;
        }
    }

    return new Object[] { ip, port };

}

From source file:com.faraox.rest.poc.provider.MyObjectMapperProvider.java

private static AnnotationIntrospector createJaxbJacksonAnnotationIntrospector() {

    final AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(
            TypeFactory.defaultInstance());
    final AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();

    return AnnotationIntrospector.pair(jacksonIntrospector, jaxbIntrospector);
}

From source file:org.camunda.spin.impl.json.jackson.format.ListJacksonJsonTypeDetector.java

protected JavaType constructType(Object object) {
    TypeFactory typeFactory = TypeFactory.defaultInstance();

    if (object instanceof List && !((List<?>) object).isEmpty()) {
        List<?> list = (List<?>) object;
        Object firstElement = list.get(0);
        return typeFactory.constructCollectionType(list.getClass(), constructType(firstElement));

    } else {/*from  w ww  . j  ava  2  s .  co m*/
        return typeFactory.constructType(object.getClass());
    }
}

From source file:com.devnexus.ting.web.JaxbJacksonObjectMapper.java

public JaxbJacksonObjectMapper() {
    final AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
    super.setAnnotationIntrospector(introspector);
}

From source file:com.thoughtworks.studios.journey.utils.JSONUtils.java

public static Map<String, Object> jsonToMap(String json) throws IOException {
    return MAPPER.readValue(json, TypeFactory.defaultInstance().constructMapType(java.util.HashMap.class,
            String.class, Object.class));
}

From source file:org.camunda.bpm.elasticsearch.util.JsonHelper.java

public static Map<String, Object> readJsonFromClasspathAsMap(String fileName) {
    InputStream inputStream = null;

    try {//from  w  w w .  j  a va 2s .  c om
        inputStream = IoUtil.getResourceAsStream(fileName);
        if (inputStream == null) {
            throw new RuntimeException("File '" + fileName + "' not found!");
        }

        MapType type = TypeFactory.defaultInstance().constructMapType(HashMap.class, String.class,
                Object.class);
        HashMap<String, Object> mapping = objectMapper.readValue(inputStream, type);

        return mapping;
    } catch (IOException e) {
        throw new RuntimeException("Unable to load json [" + fileName + "] from classpath", e);
    } finally {
        IoUtil.closeSilently(inputStream);
    }
}