List of usage examples for com.fasterxml.jackson.core.type TypeReference TypeReference
protected TypeReference()
From source file:com.vmware.photon.controller.api.client.resource.TasksApi.java
/** * Get task details asynchronously./*ww w . j ava2 s.co m*/ * * @param taskId * @param responseCallback * @throws IOException */ public void getTaskAsync(final String taskId, final FutureCallback<Task> responseCallback) throws IOException { String path = getBasePath() + "/" + taskId; getObjectByPathAsync(path, responseCallback, new TypeReference<Task>() { }); }
From source file:com.microsoft.alm.client.utils.JsonHelper.java
/** * Map to QueryParameters//from w w w.java 2s .c om * * @param model * @return Map<String, String> */ public static Map<String, String> toQueryParametersMap(final Object model) { final ObjectMapper objectMapper = getObjectMapper(); try { return objectMapper.readValue(objectMapper.writeValueAsString(model), new TypeReference<Map<String, String>>() { }); } catch (final Exception e) { log.error(e.getMessage(), e); throw new VssServiceException(e.getMessage(), e); } }
From source file:io.syndesis.model.filter.RuleFilterStep.java
default List<FilterRule> extractRules(String rulesString) { try {// w ww . j a va 2s .c om if (rulesString == null || rulesString.isEmpty()) { return null; } return Json.mapper().readValue(rulesString, new TypeReference<List<FilterRule>>() { }); } catch (IOException e) { throw new IllegalStateException(String.format("Cannot deserialize %s: %s", rulesString, e.getMessage()), e); } }
From source file:com.github.nmorel.gwtjackson.guava.jackson.ImmutablesJacksonTest.java
@Test public void testImmutableMap() { ImmutablesTester.INSTANCE//from w ww . j av a 2 s . c o m .testImmutableMap(createMapper(new TypeReference<ImmutableMap<Integer, Boolean>>() { })); }
From source file:com.github.nmorel.gwtjackson.jackson.advanced.WildcardJacksonTest.java
@Test public void testDeserializeGenericWildcard() { WildcardTester.INSTANCE/* w w w . j av a 2 s .co m*/ .testDeserializeGenericWildcard(createReader(new TypeReference<GenericWildcard<Animal>>() { })); }
From source file:com.networknt.light.rule.form.UpdFormRule.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"); String formId = (String) data.get("formId"); String error = null;//from www . ja v a 2 s . c o m 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) { // admin or formAdmin if (!host.equals(data.get("host"))) { error = "User can only update form from host: " + host; inputMap.put("responseCode", 403); } else { if (!formId.contains(host)) { error = "form id doesn't contain host: " + host; inputMap.put("responseCode", 403); } else { int inputVersion = (int) data.get("@version"); String json = getFormById(inputMap); if (json == null) { error = "Form with id " + formId + " cannot be found"; inputMap.put("responseCode", 404); } else { Map<String, Object> form = mapper.readValue(json, new TypeReference<HashMap<String, Object>>() { }); int storedVersion = (int) form.get("@version"); if (inputVersion != storedVersion) { inputMap.put("responseCode", 400); error = "Updating version " + inputVersion + " doesn't match stored version " + storedVersion; } else { Map eventMap = getEventMap(inputMap); Map<String, Object> eventData = (Map<String, Object>) eventMap.get("data"); inputMap.put("eventMap", eventMap); eventData.putAll((Map<String, Object>) inputMap.get("data")); eventData.put("updateDate", new java.util.Date()); eventData.put("updateUserId", user.get("userId")); // no need to remove host from eventData as owner update won't touch id and host. } } } } } else { // owner int inputVersion = (int) data.get("@version"); String json = getFormById(inputMap); if (json == null) { error = "Form with id " + formId + " cannot be found"; inputMap.put("responseCode", 404); } else { Map<String, Object> form = mapper.readValue(json, new TypeReference<HashMap<String, Object>>() { }); int storedVersion = (int) form.get("@version"); if (inputVersion != storedVersion) { inputMap.put("responseCode", 400); error = "Updating version " + inputVersion + " doesn't match stored version " + storedVersion; } else { Map eventMap = getEventMap(inputMap); Map<String, Object> eventData = (Map<String, Object>) eventMap.get("data"); inputMap.put("eventMap", eventMap); eventData.putAll((Map<String, Object>) inputMap.get("data")); eventData.put("updateDate", new java.util.Date()); eventData.put("updateUserId", user.get("userId")); // no need to remove host from eventData as owner update won't touch id and host. } } } if (error != null) { inputMap.put("error", error); return false; } else { return true; } }
From source file:com.spotify.helios.system.EnvironmentVariableTest.java
@Test public void test() throws Exception { startDefaultMaster();//w w w .j a v a 2 s. co m startDefaultAgent(testHost(), "--env", "SPOTIFY_POD=PODNAME", "SPOTIFY_ROLE=ROLENAME", "BAR=badfood"); awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS); // Wait for the agent to report environment vars Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<Object>() { @Override public Object call() throws Exception { final Map<String, HostStatus> status = Json.read(cli("hosts", testHost(), "--json"), new TypeReference<Map<String, HostStatus>>() { }); return status.get(testHost()).getEnvironment(); } }); try (final DockerClient dockerClient = getNewDockerClient()) { final List<String> command = asList("sh", "-c", "echo pod: $SPOTIFY_POD; " + "echo role: $SPOTIFY_ROLE; " + "echo foo: $FOO; " + "echo bar: $BAR"); // Create job final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, command, ImmutableMap.of("FOO", "4711", "BAR", "deadbeef")); // deploy deployJob(jobId, testHost()); final TaskStatus taskStatus = awaitTaskState(jobId, testHost(), EXITED); final LogStream logs = dockerClient.logs(taskStatus.getContainerId(), stdout(), stderr()); final String log = logs.readFully(); assertThat(log, containsString("pod: PODNAME")); assertThat(log, containsString("role: ROLENAME")); assertThat(log, containsString("foo: 4711")); // Verify that the the BAR environment variable in the job overrode the agent config assertThat(log, containsString("bar: deadbeef")); final Map<String, HostStatus> status = Json.read(cli("hosts", testHost(), "--json"), new TypeReference<Map<String, HostStatus>>() { }); assertEquals(ImmutableMap.of("SPOTIFY_POD", "PODNAME", "SPOTIFY_ROLE", "ROLENAME", "BAR", "badfood"), status.get(testHost()).getEnvironment()); assertEquals(ImmutableMap.of("SPOTIFY_POD", "PODNAME", "SPOTIFY_ROLE", "ROLENAME", "BAR", "deadbeef", "FOO", "4711"), status.get(testHost()).getStatuses().get(jobId).getEnv()); } }
From source file:com.evrythng.java.wrapper.service.FileService.java
/** * Finds files.// w w w.j a v a2s .com * * @param after find files starting from file name {@code after} or if {@code null} find from the beginning. * * @return a preconfigured {@link Builder} */ public Builder<List<File>> filesReader(final String after) throws EvrythngClientException { return get(PATH_FILES, new TypeReference<List<File>>() { }).queryParam(AfterQueryParamValue.after(after)); }
From source file:com.opentable.exception.ExceptionClientResponseFilter.java
@SuppressWarnings("unchecked") @Override/*from w w w . jav a 2 s .co m*/ public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException { final MediaType type = responseContext.getMediaType(); if (type == null) { return; } if (type.isCompatible(OTApiException.MEDIA_TYPE)) { final Map<String, Object> wrapper = mapper.readValue(responseContext.getEntityStream(), 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 {}", Joiner.on('\t').join(causesList)); Preconditions.checkState(causesList.get(0) instanceof Map, "bad cause"); final OTApiException exn = toException((Map<String, Object>) causesList.get(0)); if (causesList.size() > 1) { LOG.debug("Multi-exception found. first exception, remainder following.", exn); } for (int i = 1; i < causesList.size(); i++) { final OTApiException suppressed = toException((Map<String, Object>) causesList.get(i)); LOG.debug("Multiple exceptions, continuation from prior backtrace...", suppressed); exn.addSuppressed(suppressed); } throw exn; } }
From source file:rest.NoteREST.java
private Note 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>>() { };/* w w w. ja v a 2 s. co m*/ StringBuilder sb = new StringBuilder(); try { HashMap<String, Object> map = mapper.readValue(responseJson, typeReference); if (Boolean.parseBoolean(map.get("found").toString())) { return Note.parseNote(map); // } else { return null; } } catch (Exception e) { return null; } }