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.vmware.photon.controller.nsxclient.apis.FabricApi.java

/**
 * Registers a resource with NSX as a fabric node.
 *///from   w w w  .  ja  v  a 2  s .c o  m
public void registerFabricNode(FabricNodeCreateSpec request, FutureCallback<FabricNode> responseCallback)
        throws IOException {
    postAsync(FABRIC_NODES_BASE_PATH, serializeObjectAsJson(request), HttpStatus.SC_CREATED,
            new TypeReference<FabricNode>() {
            }, responseCallback);
}

From source file:com.vmware.photon.controller.api.client.resource.ApiBase.java

public final Task parseTaskFromHttpResponse(HttpResponse httpResponse) throws IOException {
    return this.restClient.parseHttpResponse(httpResponse, new TypeReference<Task>() {
    });/*  ww  w .  j  av  a  2  s .  c om*/
}

From source file:com.networknt.light.rule.user.GetAllUserRule.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 host = (String) user.get("host");
    if (host != null) {
        if (!host.equals(data.get("host"))) {
            inputMap.put("error", "You can only get all users from host: " + host);
            inputMap.put("responseCode", 403);
            return false;
        }// w w  w . j  a v a 2 s  . c o m
    } else {
        // retrieve everything as this is the owner
        data.remove("host"); // removed the host added by RestHandler.
    }
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        long total = getTotalNumberUserFromDb(graph, data);
        if (total > 0) {
            String json = getUserFromDb(graph, data);
            List<Map<String, Object>> users = mapper.readValue(json,
                    new TypeReference<List<HashMap<String, Object>>>() {
                    });
            Map<String, Object> result = new HashMap<String, Object>();
            result.put("total", total);
            result.put("users", users);
            inputMap.put("result", mapper.writeValueAsString(result));
            return true;
        } else {
            inputMap.put("error", "No user can be found.");
            inputMap.put("responseCode", 404);
            return false;
        }
    } catch (Exception e) {
        logger.error("Exception:", e);
        throw e;
    } finally {
        graph.shutdown();
    }
}

From source file:com.nesscomputing.exception.ExceptionObserver.java

@SuppressWarnings("unchecked")
@Override//from  w  w  w.j  a  v  a2  s  .  c om
public HttpClientResponse onResponseReceived(HttpClientResponse response) throws IOException {
    if (StringUtils.isBlank(response.getContentType())) {
        return response;
    }

    final MediaType type = MediaType.valueOf(response.getContentType());
    if (type.isCompatible(NessApiException.MEDIA_TYPE) || NessApiException.LEGACY_TYPES.contains(type)) {
        final Map<String, Object> wrapper = mapper.readValue(response.getResponseBodyAsStream(),
                new TypeReference<Map<String, Object>>() {
                });
        final Object causes = wrapper.get("causes");

        Preconditions.checkState(causes instanceof List, "bad causes");
        final List<?> causesList = (List<?>) causes;

        LOG.debug("Received error responses %s", Joiner.on('\t').join(causesList));

        Preconditions.checkState(causesList.get(0) instanceof Map, "bad cause");

        final NessApiException exn = toException((Map<String, Object>) causesList.get(0));

        if (causesList.size() > 1) {
            LOG.debug(exn, "Multi-exception found.  first exception, remainder following.");
        }

        for (int i = 1; i < causesList.size(); i++) {
            final NessApiException suppressed = toException((Map<String, Object>) causesList.get(1));
            LOG.debug(suppressed, "Multiple exceptions, continuation from prior backtrace...");
            exn.addSuppressed(suppressed);
        }

        throw exn;
    }

    return response;
}

From source file:wercker4j.response.ResponseWrapper.java

public List<DeploySummary> deploys() throws Wercker4jException {
    ObjectMapper objectMapper = new ObjectMapper();
    try {/*from w ww  . j  a v a2  s  . co  m*/
        return objectMapper.readValue(response, new TypeReference<List<DeploySummary>>() {
        });
    } catch (Exception e) {
        throw new Wercker4jException(e);
    }
}

From source file:com.amazonaws.demo.messageboard.MessageQueueAdapter.java

private String extractMessageFromJsonObject(String json) {
    try {/* w ww .j  a  v a 2 s  .c o  m*/
        ObjectMapper mapper = new ObjectMapper();
        Map<String, Object> jsonDic = mapper.readValue(json, new TypeReference<Map<String, Object>>() {
        });

        return (String) jsonDic.get("Message");
    } catch (Exception exception) {
        return null;
    }
}

From source file:com.netflix.suro.sink.remotefile.TestPrefixFormatter.java

@Test
public void testDynamicDate() throws IOException {
    String spec = "{\n" + "    \"type\": \"dynamic\",\n" + "    \"format\": \"date(YYYYMMDD)\"\n" + "}";

    ObjectMapper mapper = injector.getInstance(ObjectMapper.class);
    RemotePrefixFormatter formatter = mapper.readValue(spec, new TypeReference<RemotePrefixFormatter>() {
    });/*from   w  ww . ja  v a2  s.  com*/

    DateTimeFormatter format = DateTimeFormat.forPattern("YYYYMMDD");
    assertEquals(formatter.get(), format.print(new DateTime()) + "/");
}

From source file:org.freelectron.leobel.testlwa.models.AlertsFileDataStore.java

@Override
public synchronized void loadFromDisk(final AlertManager manager, final ResultListener listener) {
    sExecutor.execute(new Runnable() {
        @Override//from w w w  .  jav a2  s . co  m
        public void run() {
            FileReader fis = null;
            BufferedReader br = null;
            JsonReader parser = null;

            ObjectReader reader = ObjectMapperFactory.getObjectReader()
                    .forType(new TypeReference<List<Alert>>() {
                    });
            List<Alert> droppedAlerts = new LinkedList<Alert>();
            try {
                fis = new FileReader(ALARM_FILE);
                br = new BufferedReader(fis);

                List<Alert> alerts = reader.readValue(br);
                for (Alert alert : alerts) {
                    // Only add alerts that are within the expiration window
                    if (alert.getScheduledTime()
                            .isAfter(DateTime.now().minusMinutes(MINUTES_AFTER_PAST_ALERT_EXPIRES))) {
                        manager.add(alert, true);
                    } else {
                        droppedAlerts.add(alert);
                    }
                }
                // Now that all the valid alerts have been re-added to the alarm manager,
                // go through and explicitly drop all the alerts that were not added
                for (Alert alert : droppedAlerts) {
                    manager.drop(alert);
                }
                listener.onSuccess();
            } catch (FileNotFoundException e) {
                // This is not a fatal error
                // The alarm file might not have been created yet
                listener.onSuccess();
            } catch (IOException e) {
                Log.d("Fail", "Failed to load alerts from disk." + e.getMessage(), e);
                listener.onFailure();
            } finally {
                IOUtils.closeQuietly(parser);
                IOUtils.closeQuietly(br);
            }
        }
    });
}

From source file:org.ocsoft.olivia.models.project.ProjectConfig.java

/**
 * OliviaProject???????.<br>//from   w  ww . j a  va 2  s .c  o m
 * ?Olivia???.
 */
void load() {
    //
    Map<String, Integer> indexes = config.getAsType(BasicProjectConfigDef.ProjectNodeIndexes,
            new TypeReference<Map<String, Integer>>() {
            });
    project.sortTreeByIndexMap(indexes);

    List<String> expandedNodes = config.getAsType(BasicProjectConfigDef.ProjectExpandedNodes,
            new TypeReference<List<String>>() {
            });
    project.setExpandState(expandedNodes);

}

From source file:org.opendatakit.database.queries.BindArgs.java

public BindArgs(String fromJSON) {
    if (fromJSON == null || fromJSON.isEmpty()) {
        bindArgs = new Object[0];
        return;/*from  w  w w  .  jav  a  2  s.c om*/
    }

    TypeReference<ArrayList<Object>> type = new TypeReference<ArrayList<Object>>() {
    };
    try {
        ArrayList<Object> values = ODKFileUtils.mapper.readValue(fromJSON, type);
        if (values == null) {
            bindArgs = new Object[0];
        } else {
            bindArgs = values.toArray(new Object[values.size()]);
        }
    } catch (IOException ignored) {
        // not expected
        throw new IllegalStateException("Unable to deserialize bindArgs");
    }
}