Example usage for com.fasterxml.jackson.databind ObjectMapper readValue

List of usage examples for com.fasterxml.jackson.databind ObjectMapper readValue

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind ObjectMapper readValue.

Prototype

@SuppressWarnings("unchecked")
    public <T> T readValue(byte[] src, JavaType valueType)
            throws IOException, JsonParseException, JsonMappingException 

Source Link

Usage

From source file:com.massivcode.weatherinfoexam.utils.NetworkUtil.java

public static WeatherInfo parseJsonToCurrentWeatherInfo(String jsonString) throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();
    WeatherInfo weatherInfo = objectMapper.readValue(jsonString, WeatherInfo.class);
    return weatherInfo;
}

From source file:com.world.watch.worldwatchcron.util.PushToUser.java

public static void push(List<String> data, String userId) {
    try {/*from ww  w  . jav a  2 s . c  o m*/
        InputStream jsonStream = PushToUser.class.getResourceAsStream("/parsePush.json");
        ObjectMapper mapper = new ObjectMapper();
        PushData push = mapper.readValue(jsonStream, PushData.class);
        push.getWhere().setUsername(userId);
        push.getData().setKeywords(data);
        String json = mapper.writeValueAsString(push);

        HttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(RequestConfig.custom().build())
                .build();
        HttpPost post = new HttpPost(URL);
        post.setHeader("X-Parse-Application-Id", "WhqWj009luOxOtIH3rM9iWJICLdf0NKbgqdaui8Q");
        post.setHeader("X-Parse-REST-API-Key", "lThhKObAz1Tkt092Cl1HeZv4KLUsdATvscOaGN2y");
        post.setHeader("Content-Type", "application/json");
        logger.debug("JSON to push {}", json.toString());
        StringEntity strEntity = new StringEntity(json);
        post.setEntity(strEntity);
        httpClient.execute(post);
        logger.debug("Pushed {} to userId {}", data.toString(), userId);
    } catch (Exception ex) {
        logger.error("Push Failed for {} ", userId, ex);
    }

}

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:com.shampan.db.collections.fragment.status.UserInfo.java

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

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

public static void initializer(String path) {

    hashmapper = new HashMap<>();

    ObjectMapper mapper = new ObjectMapper();
    try {// w  ww .  j a  v  a2s. co  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:com.shampan.db.collections.fragment.status.ReferenceInfo.java

public static ReferenceInfo getRefInfo(String jsonContent) {
    ReferenceInfo refInfo = null;//from w w w .  j  a  va  2  s  . c o  m
    try {
        ObjectMapper mapper = new ObjectMapper();
        refInfo = mapper.readValue(jsonContent, ReferenceInfo.class);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return refInfo;
}

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

public static Object fromJsonString(String json, Class<? extends Object> type) throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();

    //convert json string to object
    Object obj = objectMapper.readValue(json, type);
    return type.cast(obj);
}

From source file:org.wildfly.sample.http.management.client.WildflyCassandraJaxrsClient.java

private static String prettyPrintJson(String jsonString) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    return mapper.writerWithDefaultPrettyPrinter()
            .writeValueAsString(mapper.readValue(jsonString, Object.class));
}

From source file:com.chiralBehaviors.slp.hive.hardtack.configuration.AggregatorConfiguration.java

public static AggregatorConfiguration fromYaml(InputStream yaml)
        throws JsonParseException, JsonMappingException, IOException {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    return mapper.readValue(yaml, AggregatorConfiguration.class);
}

From source file:DataLoader.java

private static Artist parse(InputStream json, Class<Artist> type) throws Exception {
    ObjectifyJacksonModule ojm = new ObjectifyJacksonModule();
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(ojm);/*from  w w w.jav a  2s. c o  m*/

    return (Artist) mapper.readValue(json, type);
}