List of usage examples for com.fasterxml.jackson.core.type TypeReference TypeReference
protected TypeReference()
From source file:com.twitter.ambrose.model.Event.java
public static Event<?> fromJson(String json) throws IOException { return JSONUtil.toObject(json, new TypeReference<Event<?>>() { });/*from www . jav a2 s . c o m*/ }
From source file:com.vmware.photon.controller.api.client.resource.SystemStatusRestApi.java
/** * Get system status asynchronously./*from www .j ava2 s. co m*/ * * @param responseCallback * @throws IOException */ @Override public void getSystemStatusAsync(final FutureCallback<SystemStatus> responseCallback) throws IOException { String path = getBasePath(); getObjectByPathAsync(path, responseCallback, new TypeReference<SystemStatus>() { }); }
From source file:com.spotify.helios.system.MultipleHostsTest.java
@Test public void testHostStatuses() throws Exception { final String aHost = testHost() + "a"; final String bHost = testHost() + "b"; startDefaultMaster();//from w w w. j a v a2s. c o m startDefaultAgent(aHost); startDefaultAgent(bHost); awaitHostStatus(aHost, UP, LONG_WAIT_SECONDS, SECONDS); awaitHostStatus(bHost, UP, LONG_WAIT_SECONDS, SECONDS); final Map<String, HostStatus> cliStatuses = new ObjectMapper().readValue(cli("hosts", "--json"), new TypeReference<Map<String, HostStatus>>() { }); assertTrue("status must contain key for " + aHost, cliStatuses.containsKey(aHost)); assertTrue("status must contain key for " + bHost, cliStatuses.containsKey(bHost)); final HeliosClient client = defaultClient(); final Map<String, HostStatus> clientStatuses = client.hostStatuses(ImmutableList.of(aHost, bHost)).get(); assertTrue("status must contain key for " + aHost, clientStatuses.containsKey(aHost)); assertTrue("status must contain key for " + bHost, clientStatuses.containsKey(bHost)); }
From source file:org.datagator.api.client.SpooledRowBuffer.java
@Override public Iterator<Object[]> iterator() { if (rowsCount <= cacheLimit) { return this.cache.iterator(); } else {/*from w ww .j ava2 s .c om*/ try { flush(); } catch (IOException ex) { throw new RuntimeException(ex); } return new Iterator<Object[]>() { private final JsonParser jp; private int rowIndex = 0; private final TypeReference<ArrayList<Object>> tr = new TypeReference<ArrayList<Object>>() { }; { try { // TODO lock cache file cacheFile.seek(0); FileReader reader = new FileReader(cacheFile.getFD()); jp = Entity.json.createParser(reader); JsonToken token = jp.nextToken(); // START_ARRAY if (!token.equals(JsonToken.START_ARRAY)) { throw new RuntimeException("Corrupted cache file"); } } catch (IOException ex) { throw new RuntimeException(ex); } } @Override public boolean hasNext() { return rowIndex < rowsCount; } @Override public Object[] next() { if (!hasNext()) { throw new NoSuchElementException("No such elememnt."); } try { rowIndex += 1; ArrayList<Object> buffer = jp.readValueAs(tr); return buffer.toArray(); } catch (IOException ex) { throw new RuntimeException(ex); } } @Override public void remove() { throw new UnsupportedOperationException("Not supported yet."); } }; } }
From source file:com.vmware.photon.controller.api.client.resource.ClusterApi.java
/** * Get details about the specified cluster. * * @param clusterId/*from w w w. ja va2 s . c o m*/ * @return * @throws IOException */ public Cluster getCluster(String clusterId) throws IOException { String path = String.format("%s/%s", getBasePath(), clusterId); HttpResponse httpResponse = this.restClient.perform(RestClient.Method.GET, path, null); this.restClient.checkResponse(httpResponse, HttpStatus.SC_OK); return this.restClient.parseHttpResponse(httpResponse, new TypeReference<Cluster>() { }); }
From source file:com.vmware.photon.controller.nsxclient.apis.LogicalSwitchApi.java
/** * Creates a logical switch.//from ww w .ja v a2s. c o m */ public void createLogicalSwitch(LogicalSwitchCreateSpec spec, FutureCallback<LogicalSwitch> responseCallback) throws IOException { postAsync(LOGICAL_SWITCHS_BASE_PATH, serializeObjectAsJson(spec), HttpStatus.SC_CREATED, new TypeReference<LogicalSwitch>() { }, responseCallback); }
From source file:si.mazi.rescu.JSONUtils.java
/** * Get a generic map holding the raw data from the JSON string to allow manual type differentiation * * @param jsonString The JSON string/*from w ww. j a v a 2s .c o m*/ * @param objectMapper The object mapper * @return The map */ public static Map<String, Object> getJsonGenericMap(String jsonString, ObjectMapper objectMapper) { AssertUtil.notNull(jsonString, "jsonString cannot be null"); AssertUtil.notNull(objectMapper, "objectMapper cannot be null"); try { return objectMapper.readValue(jsonString, new TypeReference<Map<String, Object>>() { }); } catch (IOException e) { // Rethrow as runtime exception throw new RuntimeException("Problem getting JSON generic map", e); } }
From source file:tachyon.master.EditLogOperationTest.java
@Test public void createDependencyTest() throws IOException { EditLogOperation editLogOperation = OBJECT_MAPPER.readValue(CREATE_DEPENDENCY_TYPE.getBytes(), EditLogOperation.class); // get all parameters for "CREATE_DEPENDENCY" List<Integer> parents = editLogOperation.get("parents", new TypeReference<List<Integer>>() { });//from ww w . jav a 2 s . c o m Assert.assertEquals(3, parents.size()); List<Integer> children = editLogOperation.get("children", new TypeReference<List<Integer>>() { }); Assert.assertEquals(4, children.size()); String commandPrefix = editLogOperation.getString("commandPrefix"); Assert.assertEquals("fake command", commandPrefix); List<ByteBuffer> data = editLogOperation.getByteBufferList("data"); Assert.assertEquals(1, data.size()); String decodedBase64 = new String(data.get(0).array(), "UTF-8"); Assert.assertEquals(new String(Base64.decodeBase64("AAAAAAAAAAAAAA==")), decodedBase64); String comment = editLogOperation.getString("comment"); Assert.assertEquals("Comment Test", comment); String framework = editLogOperation.getString("framework"); Assert.assertEquals("Tachyon Examples", framework); String frameworkVersion = editLogOperation.getString("frameworkVersion"); Assert.assertEquals("0.3", frameworkVersion); DependencyType dependencyType = editLogOperation.get("dependencyType", DependencyType.class); Assert.assertEquals(DependencyType.Narrow, dependencyType); Integer depId = editLogOperation.getInt("dependencyId"); Assert.assertEquals(1, depId.intValue()); Long creationTimeMs = editLogOperation.getLong("creationTimeMs"); Assert.assertEquals(1409349750338L, creationTimeMs.longValue()); }
From source file:com.netflix.suro.sink.localfile.TestSequenceFileWriter.java
@Test public void test() throws IOException { String dir = tempDir.newFolder().getAbsolutePath(); String spec = "{\n" + " \"type\": \"sequence\"\n" + "}"; ObjectMapper mapper = injector.getInstance(ObjectMapper.class); FileWriter writer = mapper.readValue(spec, new TypeReference<FileWriter>() { });/* w w w . j av a2 s . c o m*/ writer.open(dir); assertEquals(writer.getLength(), 0); writer.rotate(dir + "testfile0.suro"); for (int i = 0; i < 10; ++i) { writer.writeTo(new Message("routingKey", ("message0" + i).getBytes())); } System.out.println("length: " + writer.getLength()); assertEquals(writer.getLength(), 540); writer.rotate(dir + "testfile1.suro"); assertEquals(writer.getLength(), 100); // empty sequence file length assertEquals(checkFileContents(dir + "testfile0.suro", "message0"), 10); writer.setDone(dir + "testfile0.suro", dir + "testfile0.done"); assertFalse(new File(dir + "testfile0.suro").exists()); checkFileContents(dir + "testfile0.done", "message0"); for (int i = 0; i < 10; ++i) { writer.writeTo(new Message("routingKey", ("message1" + i).getBytes())); } writer.close(); assertEquals(checkFileContents(dir + "testfile1.suro", "message1"), 10); }
From source file:com.xeiam.xchange.mtgox.v2.service.marketdata.polling.streaming.TradeJSONTest.java
@Test public void testStreamingUnmarshal() throws IOException { // Read in the JSON from the example resources InputStream is = TradeJSONTest.class .getResourceAsStream("/v2/marketdata/streaming/example-trade-streaming-data.json"); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); Map<String, Object> userInMap = mapper.readValue(is, new TypeReference<Map<String, Object>>() { });// w w w. j av a2 s . c o m MtGoxTrade mtGoxTrade = mapper.readValue(mapper.writeValueAsString(userInMap.get("trade")), MtGoxTrade.class); // Verify that the example data was unmarshalled correctly assertThat(mtGoxTrade.getPriceInt()).isEqualTo(9079995L); assertThat(mtGoxTrade.getAmountInt()).isEqualTo(1851242L); assertThat(mtGoxTrade.getTid()).isEqualTo(1364652424875559L); }