use of org.codehaus.jackson.type.TypeReference in project android-app by eoecn.
the class BlogsDao method getMore.
public BlogsMoreResponse getMore(String more_url) {
BlogsMoreResponse response;
try {
String result = RequestCacheUtil.getRequestContent(mActivity, more_url + Utility.getScreenParams(mActivity), Constants.WebSourceType.Json, Constants.DBContentType.Content_list, true);
response = mObjectMapper.readValue(result, new TypeReference<BlogsMoreResponse>() {
});
return response;
} catch (JsonParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JsonMappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
use of org.codehaus.jackson.type.TypeReference in project pinot by linkedin.
the class GenerateDataCommand method buildCardinalityRangeMaps.
private void buildCardinalityRangeMaps(String file, HashMap<String, Integer> cardinality, HashMap<String, IntRange> range) throws JsonParseException, JsonMappingException, IOException {
List<SchemaAnnotation> saList;
if (file == null) {
// Nothing to do here.
return;
}
ObjectMapper objectMapper = new ObjectMapper();
saList = objectMapper.readValue(new File(file), new TypeReference<List<SchemaAnnotation>>() {
});
for (SchemaAnnotation sa : saList) {
String column = sa.getColumn();
if (sa.isRange()) {
range.put(column, new IntRange(sa.getRangeStart(), sa.getRangeEnd()));
} else {
cardinality.put(column, sa.getCardinality());
}
}
}
use of org.codehaus.jackson.type.TypeReference in project databus by linkedin.
the class TestRelayCommandsLocal method testRegisterV4CommandLessThanHappyPaths.
@Test
public void testRegisterV4CommandLessThanHappyPaths() throws Exception {
LOG.debug("\n\nstarting testRegisterV4CommandLessThanHappyPaths()\n");
// protocolVersion < 2
HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/register?sources=4002&" + DatabusHttpHeaders.PROTOCOL_VERSION_PARAM + "=1");
SimpleTestHttpClient httpClient = SimpleTestHttpClient.createLocal(TimeoutPolicy.ALL_TIMEOUTS);
SimpleHttpResponseHandler respHandler = httpClient.sendRequest(_serverAddress, httpRequest);
assertTrue("failed to get a response", respHandler.awaitResponseUninterruptedly(1, TimeUnit.SECONDS));
HttpResponse respObj = respHandler.getResponse();
assertNotNull("/register failed to return expected error", respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
LOG.debug("DATABUS_ERROR_CLASS_HEADER = " + respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
// protocolVersion > 4
httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/register?sources=4002&" + DatabusHttpHeaders.PROTOCOL_VERSION_PARAM + "=5");
respHandler = httpClient.sendRequest(_serverAddress, httpRequest);
assertTrue("failed to get a response", respHandler.awaitResponseUninterruptedly(1, TimeUnit.SECONDS));
respObj = respHandler.getResponse();
assertNotNull("/register failed to return expected error", respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
LOG.debug("DATABUS_ERROR_CLASS_HEADER = " + respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
// protocolVersion == 2: this is a happy path, but explicitly specifying the version is
// unusual in this case (default = version 2 or 3, which are identical for /register), so
// check for expected response
httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/register?sources=4002&" + DatabusHttpHeaders.PROTOCOL_VERSION_PARAM + "=2");
respHandler = httpClient.sendRequest(_serverAddress, httpRequest);
assertTrue("failed to get a response", respHandler.awaitResponseUninterruptedly(1, TimeUnit.SECONDS));
respObj = respHandler.getResponse();
assertNull("/register v2 returned unexpected error: " + respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER), respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
LOG.debug("DATABUS_ERROR_CLASS_HEADER = " + respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
String registerResponseProtocolVersionStr = respObj.getHeader(DatabusHttpHeaders.DBUS_CLIENT_RELAY_PROTOCOL_VERSION_HDR);
assertNotNull("/register protocol-version response header not present", registerResponseProtocolVersionStr);
assertEquals("client-relay protocol response version mismatch", "2", registerResponseProtocolVersionStr);
byte[] respBytes = respHandler.getReceivedBytes();
if (LOG.isDebugEnabled()) {
LOG.debug("/register response: " + new String(respBytes));
}
ByteArrayInputStream in = new ByteArrayInputStream(respBytes);
ObjectMapper objMapper = new ObjectMapper();
List<RegisterResponseEntry> sourceSchemasList = null;
try {
sourceSchemasList = objMapper.readValue(in, new TypeReference<List<RegisterResponseEntry>>() {
});
} catch (JsonMappingException jmex) {
Assert.fail("ObjectMapper failed unexpectedly");
}
assertNotNull("missing source schemas in response", sourceSchemasList);
assertEquals("expected one source schema", 1, sourceSchemasList.size());
RegisterResponseEntry rre = sourceSchemasList.get(0);
assertEquals("unexpected source id", 4002, rre.getId());
Schema resSchema = Schema.parse(rre.getSchema());
assertEquals("unexpected source-schema name for source id 4002", "test4.source2_v1", resSchema.getFullName());
// protocolVersion == 3: as with v2 above; just do a quick sanity check
httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/register?sources=4002&" + DatabusHttpHeaders.PROTOCOL_VERSION_PARAM + "=3");
respHandler = httpClient.sendRequest(_serverAddress, httpRequest);
assertTrue("failed to get a response", respHandler.awaitResponseUninterruptedly(1, TimeUnit.SECONDS));
respObj = respHandler.getResponse();
assertNull("/register v3 returned unexpected error: " + respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER), respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
LOG.debug("DATABUS_ERROR_CLASS_HEADER = " + respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
registerResponseProtocolVersionStr = respObj.getHeader(DatabusHttpHeaders.DBUS_CLIENT_RELAY_PROTOCOL_VERSION_HDR);
assertNotNull("/register protocol-version response header not present", registerResponseProtocolVersionStr);
assertEquals("client-relay protocol response version mismatch", "3", registerResponseProtocolVersionStr);
}
use of org.codehaus.jackson.type.TypeReference in project exhibitor by soabase.
the class ExplorerResource method getAnalyze.
@GET
@Path("analyze")
@Produces("application/json")
public Response getAnalyze(@QueryParam("request") String json) throws Exception {
ObjectMapper mapper = new ObjectMapper();
TypeReference<List<PathAnalysisRequest>> ref = new TypeReference<List<PathAnalysisRequest>>() {
};
List<PathAnalysisRequest> paths = mapper.getJsonFactory().createJsonParser(json).readValueAs(ref);
return analyze(paths);
}
use of org.codehaus.jackson.type.TypeReference in project predix-machine-template-adapter-edison by PredixDev.
the class IntelBoardSubscriptionMachineAdapter method activate.
/*
* ############################################### # OSGi service lifecycle
* management # ###############################################
*/
/**
* OSGi component lifecycle activation method
*
* @param ctx
* component context
* @throws IOException
* on fail to load/set configuration properties
*/
@Activate
public void activate(ComponentContext ctx) throws IOException {
//$NON-NLS-1$
_logger.info("Starting sample " + ctx.getBundleContext().getBundle().getSymbolicName());
ObjectMapper mapper = new ObjectMapper();
File configFile = new File(MACHINE_HOME + File.separator + this.config.getNodeConfigFile());
this.configNodes = mapper.readValue(configFile, new TypeReference<List<JsonDataNode>>() {
});
createNodes(this.configNodes);
this.adapterInfo = new MachineAdapterInfo(this.config.getAdapterName(), IntelBoardSubscriptionMachineAdapter.SERVICE_PID, this.config.getAdapterDescription(), ctx.getBundleContext().getBundle().getVersion().toString());
List<String> subs = Arrays.asList(parseDataSubscriptions());
// Start data subscription and sign up for data updates.
for (String sub : subs) {
WorkshopDataSubscription dataSubscription = new WorkshopDataSubscription(this, sub, this.config.getUpdateInterval(), new ArrayList<PDataNode>(this.dataNodes.values()), spillway);
this.dataSubscriptions.put(dataSubscription.getId(), dataSubscription);
// Using internal listener, but these subscriptions can be used with
// Spillway listener also
dataSubscription.addDataSubscriptionListener(this.dataUpdateHandler);
new Thread(dataSubscription).start();
}
}
Aggregations