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:rest.GroupREST.java

private Group getFormattedDataSingle(Response response) {
    String responseJson = response.readEntity(String.class);
    System.out.println(responseJson);
    ObjectMapper mapper = new ObjectMapper();
    TypeReference<HashMap<String, Object>> typeReference = new TypeReference<HashMap<String, Object>>() {
    };/*from  w  w w.  ja  v  a  2  s .  c  o m*/
    StringBuilder sb = new StringBuilder();
    try {
        HashMap<String, Object> map = mapper.readValue(responseJson, typeReference);
        if (Boolean.parseBoolean(map.get("found").toString())) {
            return Group.parseGroup(map);
            //               
        } else {
            return null;
        }
    } catch (Exception e) {
        return null;
    }
}

From source file:com.evrythng.java.wrapper.service.ActionService.java

/**
 * Creates an action type.//from   www  .  j av  a 2 s.  co m
 */
public Builder<ActionType> actionTypeCreator(final ActionType type) throws EvrythngClientException {

    return post(PATH_ACTIONS, type, new TypeReference<ActionType>() {

    });
}

From source file:com.spotify.helios.system.CliHostListTest.java

@Test
public void testHostListJson() throws Exception {
    final String jsonOutput = cli("hosts", "-f", "--json");
    final Map<String, HostStatus> statuses = Json.readUnchecked(jsonOutput,
            new TypeReference<Map<String, HostStatus>>() {
            });/*www .ja  v a 2 s  .  com*/
    final HeliosClient client = defaultClient();
    final Map<String, HostStatus> expectedStatuses = client.hostStatuses(ImmutableList.of(hostname1, hostname2))
            .get();
    assertThat(expectedStatuses, equalTo(statuses));
}

From source file:at.becast.youploader.account.Account.java

public static Account read(String name) throws IOException {
    PreparedStatement stmt;//ww w. j  a  va 2 s  . c  o  m
    try {
        stmt = c.prepareStatement("SELECT * FROM `accounts` WHERE `name`=? LIMIT 1");
        stmt.setString(1, name);
        ResultSet rs = stmt.executeQuery();
        ObjectMapper mapper = new ObjectMapper();
        List<Cookie> c = mapper.readValue(rs.getString("cookie"), new TypeReference<List<Cookie>>() {
        });
        int id = rs.getInt("id");
        String token = rs.getString("refresh_token");
        stmt.close();
        rs.close();
        return new Account(id, name, token, c);
    } catch (SQLException e) {
        LOG.error("Account read error!", e);
        return null;
    }
}

From source file:com.networknt.light.rule.validation.DelValidationRule.java

public boolean execute(Object... objects) throws Exception {
    Map<String, Object> inputMap = (Map<String, Object>) objects[0];
    Map<String, Object> data = (Map<String, Object>) inputMap.get("data");
    Map<String, Object> payload = (Map<String, Object>) inputMap.get("payload");
    Map<String, Object> user = (Map<String, Object>) payload.get("user");
    String error = null;/*w  w  w. java2s  .c o m*/
    String host = (String) user.get("host");
    String ruleClass = (String) data.get("ruleClass");
    if (host != null) {
        // admin or ruleAdmin deleting validation schema for their site.
        if (!host.equals(data.get("host"))) {
            error = "User can only delete validation schema from host: " + host;
            inputMap.put("responseCode", 403);
        } else {
            // check if the ruleClass belongs to the host.
            if (!ruleClass.contains(host)) {
                error = "ruleClass is not owned by the host: " + host;
                inputMap.put("responseCode", 403);
            } else {
                String json = getValidation(ruleClass);
                if (json == null) {
                    error = "Validation schema does not exist";
                    inputMap.put("responseCode", 404);
                } else {
                    Map<String, Object> jsonMap = mapper.readValue(json,
                            new TypeReference<HashMap<String, Object>>() {
                            });
                    if (jsonMap.get("createUserId") == null) {
                        // this validation rule is populated from form add/update/import and should not be updated
                        error = "schema is populated from form rules and cannot delete";
                        inputMap.put("responseCode", 400);
                    } else {
                        Map eventMap = getEventMap(inputMap);
                        Map<String, Object> eventData = (Map<String, Object>) eventMap.get("data");
                        inputMap.put("eventMap", eventMap);
                        eventData.put("ruleClass", data.get("ruleClass"));
                    }
                }
            }
        }
    } else {
        String json = getValidation(ruleClass);
        if (json == null) {
            error = "Validation schema does not exist";
            inputMap.put("responseCode", 404);
        } else {
            Map<String, Object> jsonMap = mapper.readValue(json, new TypeReference<HashMap<String, Object>>() {
            });
            if (jsonMap.get("createUserId") == null) {
                // this validation rule is populated from form add/update/import and should not be updated
                error = "schema is populated from form rules and cannot delete";
                inputMap.put("responseCode", 400);
            } else {
                Map eventMap = getEventMap(inputMap);
                Map<String, Object> eventData = (Map<String, Object>) eventMap.get("data");
                inputMap.put("eventMap", eventMap);
                eventData.put("ruleClass", data.get("ruleClass"));
            }
        }
    }

    if (error != null) {
        inputMap.put("error", error);
        return false;
    } else {
        return true;
    }
}

From source file:com.okta.sdk.clients.FactorsApiClient.java

public List<Question> getAvailableQuestions(String userId) throws IOException {
    return get(getEncodedPath("/%s/factors/questions", userId), new TypeReference<List<Question>>() {
    });/*w w w .j av a  2  s.c om*/
}

From source file:io.dropwizard.discovery.client.io.dropwizard.ranger.ServiceDiscoveryClient.java

@Builder(builderMethodName = "fromCurator", builderClassName = "FromCuratorBuilder")
ServiceDiscoveryClient(String namespace, String serviceName, String environment, ObjectMapper objectMapper,
        CuratorFramework curator) throws Exception {
    this.criteria = ShardInfo.builder().environment(environment).build();
    this.serviceFinder = ServiceFinderBuilders.<ShardInfo>shardedFinderBuilder().withCuratorFramework(curator)
            .withNamespace(namespace).withServiceName(serviceName).withDeserializer(data -> {
                try {
                    return objectMapper.readValue(data, new TypeReference<ServiceNode<ShardInfo>>() {
                    });//from   w  w  w.  jav  a2 s  .  c o m
                } catch (Exception e) {
                    log.warn("Could not parse node data", e);
                }
                return null;
            }).build();
}

From source file:com.github.nmorel.gwtjackson.jackson.advanced.GenericsJacksonTest.java

@Test
public void testSerializeIntegerGenericString() {
    GenericsTester.INSTANCE.testSerializeIntegerGenericString(
            createWriter(new TypeReference<GenericTwoType<Integer, GenericOneType<String>>>() {
            }));//w w w. j a va 2 s.  com
}

From source file:com.okta.sdk.clients.EventApiClient.java

/**
 * Returns a maximum number of Events./*from   ww w.jav  a 2s . c om*/
 *
 * @param  limit {@link Integer}                 Number of matching results to return.
 * @return {@link List}                          List of events in the search.
 * @throws IOException                           If an input or output exception occurred.
 */
public List<Event> getEventsWithLimit(int limit) throws IOException {
    return get(getEncodedPath("?" + LIMIT + "=%s", Integer.toString(limit)), new TypeReference<List<Event>>() {
    });
}

From source file:org.hawkular.datamining.itest.HawkularDataminingITest.java

@Test
public void testModelLearnAndPredict() throws Throwable {
    // create//  w w  w  .j av  a  2 s. co  m
    Metric.RestBlueprint blueprint = new Metric.RestBlueprint(metricId, 100L);
    postNewEntity("metrics", tenant, blueprint);

    // get
    Response responseGet = get("metrics", tenant);
    assertThat(responseGet.code(), is(200));

    // learn
    List<DataPoint> dataPoints = dataPoints(1L, 60);
    Response responseLearn = post("metrics/" + metricId + "/forecaster/learn", tenant, dataPoints);
    assertThat(responseLearn.code(), is(204));

    // predict
    int ahead = 5;
    Response responsePredict = get("metrics/" + metricId + "/forecaster/forecast?ahead=" + ahead, tenant);
    assertThat(responsePredict.code(), is(200));
    List<DataPoint> predicted = parseResponseBody(responsePredict, new TypeReference<List<DataPoint>>() {
    });
    assertThat(predicted.size(), is(ahead));
}