use of com.fasterxml.jackson.core.type.TypeReference in project druid by druid-io.
the class SqlResourceTest method doPost.
// Returns either an error or a result.
private Pair<QueryInterruptedException, List<Map<String, Object>>> doPost(final SqlQuery query) throws Exception {
final Response response = resource.doPost(query);
if (response.getStatus() == 200) {
final StreamingOutput output = (StreamingOutput) response.getEntity();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
output.write(baos);
return Pair.of(null, JSON_MAPPER.<List<Map<String, Object>>>readValue(baos.toByteArray(), new TypeReference<List<Map<String, Object>>>() {
}));
} else {
return Pair.of(JSON_MAPPER.readValue((byte[]) response.getEntity(), QueryInterruptedException.class), null);
}
}
use of com.fasterxml.jackson.core.type.TypeReference in project druid by druid-io.
the class WhiteListBasedDruidToTimelineEventConverter method readMap.
private ImmutableSortedMap<String, ImmutableList<String>> readMap(final String mapPath) {
String fileContent;
String actualPath = mapPath;
try {
if (Strings.isNullOrEmpty(mapPath)) {
actualPath = this.getClass().getClassLoader().getResource("defaultWhiteListMap.json").getFile();
LOGGER.info("using default whiteList map located at [%s]", actualPath);
fileContent = CharStreams.toString(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream("defaultWhiteListMap.json")));
} else {
fileContent = Files.asCharSource(new File(mapPath), Charset.forName("UTF-8")).read();
}
return mapper.reader(new TypeReference<ImmutableSortedMap<String, ImmutableList<String>>>() {
}).readValue(fileContent);
} catch (IOException e) {
throw new ISE(e, "Got an exception while parsing file [%s]", actualPath);
}
}
use of com.fasterxml.jackson.core.type.TypeReference in project feign by OpenFeign.
the class JacksonCodecTest method customEncoder.
@Test
public void customEncoder() throws Exception {
JacksonEncoder encoder = new JacksonEncoder(Arrays.<Module>asList(new SimpleModule().addSerializer(Zone.class, new ZoneSerializer())));
List<Zone> zones = new LinkedList<Zone>();
zones.add(new Zone("denominator.io."));
zones.add(new Zone("denominator.io.", "abcd"));
RequestTemplate template = new RequestTemplate();
encoder.encode(zones, new TypeReference<List<Zone>>() {
}.getType(), template);
assertThat(template).hasBody(//
"" + "[ {\n" + " \"name\" : \"DENOMINATOR.IO.\"\n" + "}, {\n" + " \"name\" : \"DENOMINATOR.IO.\",\n" + " \"id\" : \"ABCD\"\n" + "} ]");
}
use of com.fasterxml.jackson.core.type.TypeReference in project feign by OpenFeign.
the class JacksonCodecTest method encodesFormParams.
@Test
public void encodesFormParams() throws Exception {
Map<String, Object> form = new LinkedHashMap<String, Object>();
form.put("foo", 1);
form.put("bar", Arrays.asList(2, 3));
RequestTemplate template = new RequestTemplate();
new JacksonEncoder().encode(form, new TypeReference<Map<String, ?>>() {
}.getType(), template);
assertThat(template).hasBody(//
"" + //
"{\n" + //
" \"foo\" : 1,\n" + //
" \"bar\" : [ 2, 3 ]\n" + "}");
}
use of com.fasterxml.jackson.core.type.TypeReference in project pinot by linkedin.
the class Utils method convertToMetricExpressions.
public static List<MetricExpression> convertToMetricExpressions(String metricsJson, MetricAggFunction aggFunction, String collection) throws ExecutionException {
List<MetricExpression> metricExpressions = new ArrayList<>();
if (metricsJson == null) {
return metricExpressions;
}
ArrayList<String> metricExpressionNames;
try {
TypeReference<ArrayList<String>> valueTypeRef = new TypeReference<ArrayList<String>>() {
};
metricExpressionNames = OBJECT_MAPPER.readValue(metricsJson, valueTypeRef);
} catch (Exception e) {
LOG.warn("Expected json expression for metric [{}], adding as it is. Error in json parsing : [{}]", metricsJson, e.getMessage());
metricExpressionNames = new ArrayList<>();
String[] metrics = metricsJson.split(",");
for (String metric : metrics) {
metricExpressionNames.add(metric.trim());
}
}
for (String metricExpressionName : metricExpressionNames) {
String derivedMetricExpression = ThirdEyeUtils.getDerivedMetricExpression(metricExpressionName, collection);
MetricExpression metricExpression = new MetricExpression(metricExpressionName, derivedMetricExpression, aggFunction);
metricExpressions.add(metricExpression);
}
return metricExpressions;
}
Aggregations