Search in sources :

Example 1 with SerializeException

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);
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) SerializeException(com.baidu.hugegraph.rest.SerializeException) JsonNode(com.fasterxml.jackson.databind.JsonNode) List(java.util.List) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with SerializeException

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);
    }
}
Also used : GraphAttachable(com.baidu.hugegraph.structure.constant.GraphAttachable) SerializeException(com.baidu.hugegraph.rest.SerializeException) SerializeException(com.baidu.hugegraph.rest.SerializeException) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with SerializeException

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);
    }
}
Also used : Line(com.baidu.hugegraph.loader.reader.line.Line) ReadException(com.baidu.hugegraph.loader.exception.ReadException) SerializeException(com.baidu.hugegraph.rest.SerializeException)

Aggregations

SerializeException (com.baidu.hugegraph.rest.SerializeException)3 ReadException (com.baidu.hugegraph.loader.exception.ReadException)1 Line (com.baidu.hugegraph.loader.reader.line.Line)1 GraphAttachable (com.baidu.hugegraph.structure.constant.GraphAttachable)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1