use of com.baidu.hugegraph.rest.SerializeException in project incubator-hugegraph-toolchain by apache.
the class ToolManager method readList.
@SuppressWarnings("unchecked")
protected <T> List<T> readList(String key, Class<T> clazz, String content) {
ObjectMapper mapper = this.client.mapper();
try {
JsonNode root = mapper.readTree(content);
JsonNode element = root.get(key);
if (element == null) {
throw new SerializeException("Can't find value of the key: %s in json.", key);
} else {
JavaType t = mapper.getTypeFactory().constructParametricType(List.class, clazz);
return (List<T>) mapper.readValue(element.toString(), t);
}
} catch (IOException e) {
throw new SerializeException("Failed to deserialize %s", e, content);
}
}
use of com.baidu.hugegraph.rest.SerializeException in project incubator-hugegraph-toolchain by apache.
the class ResultSet method get.
public Result get(int index) {
if (index >= this.data.size()) {
return null;
}
Object object = this.data().get(index);
if (object == null) {
return null;
}
Class<?> clazz = this.parseResultClass(object);
// Primitive type
if (clazz.equals(object.getClass())) {
return new Result(object);
}
try {
String rawValue = MAPPER.writeValueAsString(object);
object = MAPPER.readValue(rawValue, clazz);
if (object instanceof GraphAttachable) {
((GraphAttachable) object).attachManager(graphManager);
}
return new Result(object);
} catch (Exception e) {
throw new SerializeException("Failed to deserialize: %s", e, object);
}
}
use of com.baidu.hugegraph.rest.SerializeException in project incubator-hugegraph-toolchain by apache.
the class JsonLineParser method parse.
@Override
public Line parse(String[] header, String rawLine) {
Map<String, Object> keyValues;
try {
keyValues = JsonUtil.convertMap(rawLine, String.class, Object.class);
String[] names = names(keyValues);
Object[] values = values(keyValues, names);
return new Line(rawLine, names, values);
} catch (SerializeException e) {
throw new ReadException(rawLine, "Deserialize line '%s' error", e, rawLine);
}
}
Aggregations