Example usage for com.fasterxml.jackson.core.type TypeReference TypeReference

List of usage examples for com.fasterxml.jackson.core.type TypeReference TypeReference

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core.type TypeReference TypeReference.

Prototype

protected TypeReference() 

Source Link

Usage

From source file:com.cloudera.parcel.components.JsonPermissionsParser.java

public JsonPermissionsParser() {
    super(new TypeReference<PermissionsDescriptorImpl>() {
    });
}

From source file:org.dhara.portal.web.restClientService.RestServiceImpl.java

/**
 * @see org.dhara.portal.web.restClientService.RestService#getExperiments()
 *//*www.  j a v  a 2  s  .  com*/
@Override
public List<ExperimentHelper> getExperiments() throws IOException {
    String response = getRestClient()
            .getResponse(getRestServiceConfig().getServerUrl() + RestResourceUtils.EXPERIMENTDATA_RESOURCE);
    ObjectMapper mapper = new ObjectMapper();
    return mapper.readValue(response, new TypeReference<List<ExperimentHelper>>() {
    });
}

From source file:com.comcast.cdn.traffic_control.traffic_router.core.external.ZonesTest.java

@Test
public void itGetsStatsForZones() throws Exception {
    HttpGet httpGet = new HttpGet("http://localhost:3333/crs/stats/zones/caches");
    CloseableHttpResponse response = null;

    try {// ww w  .  j a  va2 s .c  o m
        response = httpClient.execute(httpGet);
        String actual = EntityUtils.toString(response.getEntity());

        Map<String, Object> zoneStats = new ObjectMapper().readValue(actual,
                new TypeReference<HashMap<String, Object>>() {
                });

        Map<String, Object> dynamicZonesStats = (Map<String, Object>) zoneStats.get("dynamicZoneCaches");
        assertThat(dynamicZonesStats.keySet(),
                containsInAnyOrder("requestCount", "evictionCount", "totalLoadTime", "averageLoadPenalty",
                        "hitCount", "loadSuccessCount", "missRate", "loadExceptionRate", "hitRate", "missCount",
                        "loadCount", "loadExceptionCount"));

        Map<String, Object> staticZonesStats = (Map<String, Object>) zoneStats.get("staticZoneCaches");
        assertThat(staticZonesStats.keySet(),
                containsInAnyOrder("requestCount", "evictionCount", "totalLoadTime", "averageLoadPenalty",
                        "hitCount", "loadSuccessCount", "missRate", "loadExceptionRate", "hitRate", "missCount",
                        "loadCount", "loadExceptionCount"));

    } finally {
        if (response != null)
            response.close();
    }
}

From source file:com.ksmpartners.ernie.model.SerializationTest.java

@Test
public void testLists() throws Exception {
    TestClass obj1 = new TestClass("test_name1", 1);
    TestClass obj2 = new TestClass("test_name2", 2);

    List<TestClass> objList = new ArrayList<TestClass>();

    objList.add(obj1);/*from  ww  w  .  j av a2  s  .c om*/
    objList.add(obj2);

    String json = TestUtil.serialize(objList);
    List<TestClass> newList = TestUtil.MAPPER.readValue(json, new TypeReference<List<TestClass>>() {
    });

    Assert.assertEquals(json, "[{\"name\":\"test_name1\",\"id\":1},{\"name\":\"test_name2\",\"id\":2}]");
    Assert.assertTrue(TestUtil.equal(objList, newList));
}

From source file:org.ocsoft.olivia.utils.JsonUtils.java

/**
 * /* www  . j  av  a  2s.  co  m*/
 * @param value
 * @return
 * @throws IOException
 */
public static Map<String, String> readJsonStringAsStringMap(String value) throws IOException {
    return mapper.readValue(value, new TypeReference<Map<String, String>>() {
    });
}

From source file:com.pa165.ddtroops.console.client.Application.java

/**
 * Pring all heroes to console window//from  w  w w.  jav  a2s.  co  m
 */
private static void getAllHeroes() {
    try {

        URL url = new URL("http://localhost:8080/pa165/rest-jersey-server/hero");
        URLConnection connection = url.openConnection();
        connection.setDoOutput(true);
        connection.setRequestProperty("Content-Type", "application/json");
        connection.setConnectTimeout(5000);
        connection.setReadTimeout(5000);

        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String s = "";
        List<HeroDTO> hero = new ArrayList<HeroDTO>();
        while ((s = in.readLine()) != null) {
            hero = mapper.readValue(s, new TypeReference<List<HeroDTO>>() {
            });
        }
        System.out.println("All heroes");
        for (HeroDTO h : hero) {
            System.out.println("ID: " + h.getId() + ", NAME: " + h.getName() + ", RACE: " + h.getRace()
                    + ", XP: " + h.getXp());
        }
        System.out.println();
        in.close();
    } catch (Exception e) {
        System.out.println("\nError when returning all heroes");
        System.out.println(e);
    }
}

From source file:com.ysheng.auth.common.restful.BaseClient.java

/**
 * Performs a synchronous POST operation.
 *
 * @param path The path of the RESTful operation.
 * @param payload The payload of the RESTful operation.
 * @param expectedHttpStatus The expected HTTP status of the operation.
 * @param <T> The type of the response.
 * @return The response of the RESTful operation.
 * @throws IOException The error that contains detail information.
 *///from  w ww. jav a2s . c  om
public final <T> T post(final String path, final Object payload, final int expectedHttpStatus)
        throws IOException {
    HttpResponse httpResponse = restClient.perform(RestClient.Method.POST, path,
            JsonSerializer.serialize(payload));

    restClient.checkResponse(httpResponse, expectedHttpStatus);

    return JsonSerializer.deserialize(httpResponse.getEntity(), new TypeReference<T>() {
    });
}

From source file:com.cloudera.parcel.components.JsonAlternativesParser.java

public JsonAlternativesParser() {
    super(new TypeReference<AlternativesDescriptorImpl>() {
    });
}

From source file:mayoapp.migrations.V0075_0003__update_tenant_configurations.java

@Override
public void migrate(Connection connection) throws Exception {
    connection.setAutoCommit(false);//  www  .  j av  a  2 s  .  c  om

    Statement queryIdsStatement = connection.createStatement();
    ResultSet tenants = queryIdsStatement.executeQuery("SELECT entity_id, slug, configuration FROM entity "
            + "INNER JOIN tenant ON entity.id = tenant.entity_id");

    Map<UUID, ConfigurationAndName> tenantsData = Maps.newHashMap();

    while (tenants.next()) {
        String json = tenants.getString("configuration");
        String name = tenants.getString("slug");
        ObjectMapper objectMapper = new ObjectMapper();
        Map<String, Object> configuration = objectMapper.readValue(json,
                new TypeReference<Map<String, Object>>() {
                });
        if (configuration.containsKey("general")) {
            Map<String, Object> generalConfiguration = (Map<String, Object>) configuration.get("general");
            if (generalConfiguration.containsKey("name")) {
                name = (String) generalConfiguration.get("name");
                ((Map<String, Object>) configuration.get("general")).remove("name");
                json = objectMapper.writeValueAsString(configuration);
            }

        }
        ConfigurationAndName configurationAndName = new ConfigurationAndName(json, name);
        tenantsData.put((UUID) tenants.getObject("entity_id"), configurationAndName);
    }

    queryIdsStatement.close();

    PreparedStatement statement = connection
            .prepareStatement("UPDATE tenant SET name=?, configuration=? WHERE entity_id =?");

    for (UUID id : tenantsData.keySet()) {
        statement.setString(1, tenantsData.get(id).getName());
        statement.setString(2, tenantsData.get(id).getConfiguration());
        statement.setObject(3, new PG_UUID(id));
        statement.addBatch();
    }

    try {
        statement.executeBatch();
    } finally {
        statement.close();
    }
}

From source file:com.chalmers.feedlr.parser.TwitterJSONParser.java

public List<TwitterItem> parseTweets(String json) {
    long time = System.currentTimeMillis();

    if (tweetReader == null) {
        tweetReader = mapper.reader(new TypeReference<List<TwitterItem>>() {
        });/* w  w w  . j  a va  2s .co m*/
    }

    List<TwitterItem> list = null;

    try {
        list = tweetReader.readValue(json);
    } catch (JsonParseException e) {
        Log.e(getClass().getName(), e.getMessage());
    } catch (JsonMappingException e) {
        Log.e(getClass().getName(), e.getMessage());
    } catch (IOException e) {
        Log.e(getClass().getName(), e.getMessage());
    }

    Log.i(TwitterJSONParser.class.getName(), "Data binding parse");
    Log.i(TwitterJSONParser.class.getName(), "Items: " + list.size());
    Log.i(TwitterJSONParser.class.getName(), "Time in millis: " + (System.currentTimeMillis() - time));

    return list;
}