private String mapToJson(Map<String, ByteIterator> values) { VPackBuilder builder = new VPackBuilder().add(ValueType.OBJECT); for (Map.Entry<String, ByteIterator> entry : values.entrySet()) { builder.add(entry.getKey(), byteIteratorToString(entry.getValue())); } builder.close(); return arangoDB.util().deserialize(builder.slice(), String.class); }
@SuppressWarnings({ "hiding", "unchecked" }) protected <E> Collection<E> deserializeEdges(final Class<E> edgeClass, final VPackSlice next) throws VPackException { final Collection<E> edges = new ArrayList<E>(); for (final Iterator<VPackSlice> iteratorEdge = next.get("edges").arrayIterator(); iteratorEdge.hasNext();) { edges.add((E) util(Serializer.CUSTOM).deserialize(iteratorEdge.next(), edgeClass)); } return edges; }
@SuppressWarnings("unchecked") protected <T> T createResult(final Type type, final Response response) { return (T) ((type != Void.class && response.getBody() != null) ? util.deserialize(response.getBody(), type) : null); }
@Override public GraphEntity deserialize(final Response response) throws VPackException { return util().deserialize(response.getBody().get(GRAPH), GraphEntity.class); } };
@Override public GraphEntity deserialize(final Response response) throws VPackException { return util().deserialize(response.getBody().get(GRAPH), GraphEntity.class); } };
@Override public T deserialize(final Response response) throws VPackException { return util(Serializer.CUSTOM).deserialize(response.getBody().get(VERTEX), type); } };
@Override public DatabaseEntity deserialize(final Response response) throws VPackException { return util().deserialize(response.getBody().get(ArangoResponseField.RESULT), DatabaseEntity.class); } };
@Override public ServerRole deserialize(final Response response) throws VPackException { return util().deserialize(response.getBody().get("role"), ServerRole.class); } };
@Override public EdgeEntity deserialize(final Response response) throws VPackException { final VPackSlice body = response.getBody().get(EDGE); final EdgeEntity doc = util().deserialize(body, EdgeEntity.class); final Map<DocumentField.Type, String> values = new HashMap<DocumentField.Type, String>(); values.put(DocumentField.Type.ID, doc.getId()); values.put(DocumentField.Type.KEY, doc.getKey()); values.put(DocumentField.Type.REV, doc.getRev()); executor.documentCache().setValues(value, values); return doc; } };
@Override public VertexEntity deserialize(final Response response) throws VPackException { final VPackSlice body = response.getBody().get(VERTEX); final VertexEntity doc = util().deserialize(body, VertexEntity.class); final Map<DocumentField.Type, String> values = new HashMap<DocumentField.Type, String>(); values.put(DocumentField.Type.ID, doc.getId()); values.put(DocumentField.Type.KEY, doc.getKey()); values.put(DocumentField.Type.REV, doc.getRev()); executor.documentCache().setValues(value, values); return doc; } };
@Override public VertexUpdateEntity deserialize(final Response response) throws VPackException { final VPackSlice body = response.getBody().get(VERTEX); final VertexUpdateEntity doc = util().deserialize(body, VertexUpdateEntity.class); final Map<DocumentField.Type, String> values = new HashMap<DocumentField.Type, String>(); values.put(DocumentField.Type.REV, doc.getRev()); executor.documentCache().setValues(value, values); return doc; } };
@Override public EdgeUpdateEntity deserialize(final Response response) throws VPackException { final VPackSlice body = response.getBody().get(EDGE); final EdgeUpdateEntity doc = util().deserialize(body, EdgeUpdateEntity.class); final Map<DocumentField.Type, String> values = new HashMap<DocumentField.Type, String>(); values.put(DocumentField.Type.REV, doc.getRev()); executor.documentCache().setValues(value, values); return doc; } };
@Override public Collection<String> deserialize(final Response response) throws VPackException { final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT); return util().deserialize(result, new Type<Collection<String>>() { }.getType()); } };
@Override public Collection<GraphEntity> deserialize(final Response response) throws VPackException { return util().deserialize(response.getBody().get("graphs"), new Type<Collection<GraphEntity>>() { }.getType()); } };
@Override public Collection<IndexEntity> deserialize(final Response response) throws VPackException { return util().deserialize(response.getBody().get("indexes"), new Type<Collection<IndexEntity>>() { }.getType()); } };
@Override public Collection<CollectionEntity> deserialize(final Response response) throws VPackException { final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT); return util().deserialize(result, new Type<Collection<CollectionEntity>>() { }.getType()); } };
protected Response createResponse(final Message message) throws VPackParserException { final Response response = util.deserialize(message.getHead(), Response.class); if (message.getBody() != null) { response.setBody(message.getBody()); } return response; }
@Override public Collection<UserEntity> deserialize(final Response response) throws VPackException { final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT); return util().deserialize(result, new Type<Collection<UserEntity>>() { }.getType()); } };
@Override public T deserialize(final Response response) throws VPackException { final VPackSlice body = response.getBody(); if (body != null) { final VPackSlice result = body.get(ArangoResponseField.RESULT); if (!result.isNone() && !result.isNull()) { return util(Serializer.CUSTOM).deserialize(result, type); } } return null; } };
@Override public Collection<AqlFunctionEntity> deserialize(final Response response) throws VPackException { final VPackSlice body = response.getBody(); // compatibility with ArangoDB < 3.4 // https://docs.arangodb.com/devel/Manual/ReleaseNotes/UpgradingChanges34.html final VPackSlice result = body.isArray() ? body : body.get(ArangoResponseField.RESULT); return util().deserialize(result, new Type<Collection<AqlFunctionEntity>>() { }.getType()); } };