use of org.codehaus.jackson.JsonNode in project perun by CESNET.
the class JsonDeserializer method readList.
@Override
public <T> List<T> readList(String name, Class<T> valueType) throws RpcException {
JsonNode node;
if (name == null) {
// The object is not under root, but directly in the response
node = root;
name = "root";
} else {
node = root.get(name);
}
if (node == null) {
throw new RpcException(RpcException.Type.MISSING_VALUE, name);
}
if (node.isNull()) {
return null;
}
if (!node.isArray()) {
throw new RpcException(RpcException.Type.CANNOT_DESERIALIZE_VALUE, node.toString() + " as List<" + valueType.getSimpleName() + "> - not an array");
}
try {
List<T> list = new ArrayList<>(node.size());
for (JsonNode e : node) {
list.add(mapper.readValue(e, valueType));
}
return list;
} catch (IOException ex) {
throw new RpcException(RpcException.Type.CANNOT_DESERIALIZE_VALUE, node.toString() + " as List<" + valueType.getSimpleName() + ">", ex);
}
}
use of org.codehaus.jackson.JsonNode in project perun by CESNET.
the class JsonDeserializer method read.
@Override
public <T> T read(String name, Class<T> valueType) throws RpcException {
JsonNode node;
if (name == null) {
// The object is not under root, but directly in the response
node = root;
name = "root";
} else {
node = root.get(name);
}
if (node == null) {
throw new RpcException(RpcException.Type.MISSING_VALUE, name);
}
if (node.isNull()) {
return null;
}
if (!node.isObject()) {
throw new RpcException(RpcException.Type.CANNOT_DESERIALIZE_VALUE, node.toString() + " as " + valueType.getSimpleName());
}
try {
return mapper.readValue(node, valueType);
} catch (IOException ex) {
throw new RpcException(RpcException.Type.CANNOT_DESERIALIZE_VALUE, node.toString() + " as " + valueType.getSimpleName(), ex);
}
}
use of org.codehaus.jackson.JsonNode in project perun by CESNET.
the class JsonDeserializer method read.
@Override
public <T> T read(String name, Class<T> valueType) throws RpcException {
JsonNode node;
if (name == null) {
// The object is not under root, but directly in the response
node = root;
name = "root";
} else {
node = root.get(name);
}
if (node == null) {
throw new RpcException(RpcException.Type.MISSING_VALUE, name);
}
if (node.isNull()) {
return null;
}
if (!node.isObject()) {
throw new RpcException(RpcException.Type.CANNOT_DESERIALIZE_VALUE, node.toString() + " as " + valueType.getSimpleName());
}
try {
return mapper.readValue(node, valueType);
} catch (IOException ex) {
throw new RpcException(RpcException.Type.CANNOT_DESERIALIZE_VALUE, node.toString() + " as " + valueType.getSimpleName(), ex);
}
}
use of org.codehaus.jackson.JsonNode in project perun by CESNET.
the class JsonDeserializer method readListPerunBeans.
@Override
public List<PerunBean> readListPerunBeans(String name) throws RpcException {
JsonNode node;
if (name == null) {
// The object is not under root, but directly in the response
node = root;
name = "root";
} else {
node = root.get(name);
}
if (node == null) {
throw new RpcException(RpcException.Type.MISSING_VALUE, name);
}
if (node.isNull()) {
return null;
}
if (!node.isArray()) {
throw new RpcException(RpcException.Type.CANNOT_DESERIALIZE_VALUE, node.toString() + " as List<PerunBean> - not an array");
}
try {
List<PerunBean> list = new ArrayList<>(node.size());
for (JsonNode e : node) {
String beanName = e.get("beanName").getTextValue();
if (beanName == null) {
throw new RpcException(RpcException.Type.CANNOT_DESERIALIZE_VALUE, node.toString() + " as List<PerunBean> - missing beanName info");
}
list.add((PerunBean) mapper.readValue(e, Class.forName("cz.metacentrum.perun.core.api." + beanName)));
}
return list;
} catch (ClassNotFoundException ex) {
throw new RpcException(RpcException.Type.CANNOT_DESERIALIZE_VALUE, node.toString() + " as List<PerunBean> - class not found");
} catch (IOException ex) {
throw new RpcException(RpcException.Type.CANNOT_DESERIALIZE_VALUE, node.toString() + " as List<PerunBean>", ex);
}
}
use of org.codehaus.jackson.JsonNode in project YCSB by brianfrankcooper.
the class TestMeasurementsExporter method testJSONArrayMeasurementsExporter.
@Test
public void testJSONArrayMeasurementsExporter() throws IOException {
Properties props = new Properties();
props.put(Measurements.MEASUREMENT_TYPE_PROPERTY, "histogram");
Measurements mm = new Measurements(props);
ByteArrayOutputStream out = new ByteArrayOutputStream();
JSONArrayMeasurementsExporter export = new JSONArrayMeasurementsExporter(out);
long min = 5000;
long max = 100000;
ZipfianGenerator zipfian = new ZipfianGenerator(min, max);
for (int i = 0; i < 1000; i++) {
int rnd = zipfian.nextValue().intValue();
mm.measure("UPDATE", rnd);
}
mm.exportMeasurements(export);
export.close();
ObjectMapper mapper = new ObjectMapper();
JsonNode json = mapper.readTree(out.toString("UTF-8"));
assertTrue(json.isArray());
assertEquals(json.get(0).get("measurement").asText(), "Operations");
assertEquals(json.get(4).get("measurement").asText(), "MaxLatency(us)");
assertEquals(json.get(11).get("measurement").asText(), "4");
}
Aggregations