List of usage examples for com.fasterxml.jackson.core.type TypeReference TypeReference
protected TypeReference()
From source file:com.vmware.photon.controller.api.client.resource.ClusterApi.java
/** * Get details about the specified cluster. * * @param clusterId//ww w .j a v a 2 s. co m * @param responseCallback * @throws IOException */ public void getClusterAsync(final String clusterId, final FutureCallback<Cluster> responseCallback) throws IOException { final String path = String.format("%s/%s", getBasePath(), clusterId); getObjectByPathAsync(path, responseCallback, new TypeReference<Cluster>() { }); }
From source file:blueprint.sdk.util.map.KeyValueStore.java
/** * Load JSON file and populate key/value map * * @throws IOException Can't read JSON file * @throws JsonMappingException Invalid JSON mapping * @throws JsonParseException Invalid JSON file */// w w w .j a v a 2s .co m public void load() throws IOException { if (jsonFile == null) { throw new NullPointerException("JSON file is not specified"); } if (jsonFile.exists()) { TypeReference<HashMap<String, T>> typeRef = new TypeReference<HashMap<String, T>>() { }; HashMap<String, T> map = mapper.readValue(jsonFile, typeRef); synchronized (lock) { kvMap.clear(); kvMap.putAll(map); } } else { throw new FileNotFoundException("JSON file is not exist"); } }
From source file:com.vsct.strowgr.monitoring.aggregator.nsq.NsqLookupClient.java
public Set<String> getTopics() throws UnavailableNsqException { try {/*from w ww. jav a 2s. com*/ LOGGER.info("Listing all nsq topics"); HttpGet uri = new HttpGet("http://" + host + ":" + port + TOPICS_ENDPOINT); return client.execute(uri, new ResponseHandler<Set<String>>() { @Override public Set<String> handleResponse(HttpResponse httpResponse) throws ClientProtocolException, IOException { int status = httpResponse.getStatusLine().getStatusCode(); if (status >= 200 && status < 300) { HttpEntity entity = httpResponse.getEntity(); NsqLookupResponse<NsqLookupTopics> nsqResponse = mapper.readValue(entity.getContent(), new TypeReference<NsqLookupResponse<NsqLookupTopics>>() { }); return nsqResponse.data.topics; } else { throw new ClientProtocolException("Unexpected response status: " + status); } } }); } catch (IOException e) { LOGGER.error("error while querying nsqlookup for list of topics"); throw new UnavailableNsqException(e); } }
From source file:rest.MessageThreadREST.java
private MessageThread 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 2s . c o m*/ StringBuilder sb = new StringBuilder(); try { HashMap<String, Object> map = mapper.readValue(responseJson, typeReference); if (Boolean.parseBoolean(map.get("found").toString())) { return MessageThread.parseThread(map); } else { return null; } } catch (Exception e) { return null; } }
From source file:com.evrythng.java.wrapper.service.PlaceService.java
/** * Updates the referenced {@link Place}. * <p>/*from w w w . jav a 2 s . co m*/ * PUT {@value #PATH_PLACE} * * @param placeId place id * @param place {@link Place} instance * @return the updated place */ public Builder<Place> placeUpdater(final String placeId, final Place place) throws EvrythngClientException { return put(String.format(PATH_PLACE, placeId), place, new TypeReference<Place>() { }); }
From source file:com.meltmedia.dropwizard.etcd.cluster.ClusterProcessorIT.java
@Before public void setUp() throws Exception { ObjectMapper mapper = new ObjectMapper(); executor = Executors.newScheduledThreadPool(4, Executors.defaultThreadFactory()); lifecycle = mock(ClusterProcessLifecycle.class); service = ClusterProcessor.<NodeData>builder().withMapper(mapper) .withDirectory(factoryRule.getFactory().newDirectory("/jobs", new TypeReference<ClusterProcess>() { })).withLifecycleFactory(d -> lifecycle).withNodeId("1").withType(new TypeReference<NodeData>() { }).build();// w ww .j av a2 s. c o m dao = new EtcdDirectoryDao<ClusterProcess>(etcdClientSupplier::getClient, "/test/jobs", mapper, new TypeReference<ClusterProcess>() { }); service.start(); }
From source file:org.hawkular.apm.server.jms.trace.TraceStoreMDB.java
@PostConstruct public void init() { setRetryPublisher(tracePublisher);// w w w. ja va 2s . c om setTypeReference(new TypeReference<java.util.List<Trace>>() { }); setProcessor(new AbstractProcessor<Trace, Void>(ProcessorType.ManyToMany) { @Override public List<Void> processManyToMany(String tenantId, List<Trace> items) throws RetryAttemptException { try { traceService.storeFragments(tenantId, items); } catch (StoreException se) { throw new RetryAttemptException(se); } return null; } }); }
From source file:com.evrythng.java.wrapper.util.JSONUtilsTest.java
@Test public void deserializeLessInSubObject() { String json = "{\"myProp\":\"1\",\"b\":2, \"sub\": {\"y\":33} }"; MyObject o = JSONUtils.read(json, new TypeReference<MyObject>() { });//from w ww. j a v a2 s . com Assert.assertEquals("1", o.getMyProp()); Assert.assertEquals(Integer.valueOf(2), o.getB()); Assert.assertNotNull(o.getSub()); Assert.assertSame(MySubObject.class, o.getSub().getClass()); Assert.assertNull(o.getSub().getX()); Assert.assertEquals(Integer.valueOf(33), o.getSub().getY()); }
From source file:org.talend.components.dataprep.connection.DataPrepStreamMapper.java
public boolean initIterator() throws IOException { boolean hasMetRecords = false; int level = 0; while (!hasMetRecords) { final JsonToken currentToken = jsonParser.nextToken(); if (currentToken == null) { return false; // EOF }//from w ww . java 2 s . c o m switch (currentToken) { case START_OBJECT: level++; break; case END_OBJECT: level--; break; case FIELD_NAME: if ("records".equals(jsonParser.getText()) && level == 1) { hasMetRecords = true; } break; } } // Create iterator to the records in "records" element if (hasMetRecords) { jsonParser.nextToken(); // Field jsonParser.nextToken(); // Start object if (jsonParser.getCurrentToken() == JsonToken.START_OBJECT) { this.iterator = objectMapper.readValues(jsonParser, new TypeReference<Map<String, String>>() { }); return true; } } return false; }