Java Code Examples for com.arangodb.velocypack.VPackBuilder#slice()

The following examples show how to use com.arangodb.velocypack.VPackBuilder#slice() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VPackExample.java    From arangodb-java-driver-async with Apache License 2.0 6 votes vote down vote up
@Test
public void buildObject() throws VPackException {
	final VPackBuilder builder = new VPackBuilder();
	builder.add(ValueType.OBJECT);// object start
	builder.add("foo", 1); // add field "foo" with value 1
	builder.add("bar", 2); // add field "bar" with value 2
	builder.close();// object end

	final VPackSlice slice = builder.slice(); // create slice
	assertThat(slice.isObject(), is(true));
	assertThat(slice.size(), is(2)); // number of fields

	final VPackSlice foo = slice.get("foo"); // get field "foo"
	assertThat(foo.isInteger(), is(true));
	assertThat(foo.getAsInt(), is(1));

	final VPackSlice bar = slice.get("bar"); // get field "bar"
	assertThat(bar.isInteger(), is(true));
	assertThat(bar.getAsInt(), is(2));

	// iterate over the fields
	for (final Iterator<Entry<String, VPackSlice>> iterator = slice.objectIterator(); iterator.hasNext();) {
		final Entry<String, VPackSlice> field = iterator.next();
		assertThat(field.getValue().isInteger(), is(true));
	}
}
 
Example 2
Source File: VPackExample.java    From arangodb-java-driver-async with Apache License 2.0 6 votes vote down vote up
@Test
public void buildObjectInObject() throws VPackException {
	final VPackBuilder builder = new VPackBuilder();
	builder.add(ValueType.OBJECT);// object start
	builder.add("foo", ValueType.OBJECT); // add object in field "foo"
	builder.add("bar", 2); // add field "bar" with value 2 to object "foo"
	builder.close();// object "foo" end
	builder.close();// object end

	final VPackSlice slice = builder.slice(); // create slice
	assertThat(slice.isObject(), is(true));

	final VPackSlice foo = slice.get("foo");
	assertThat(foo.isObject(), is(true));

	final VPackSlice bar = foo.get("bar"); // get field "bar" from "foo"
	assertThat(bar.isInteger(), is(true));
}
 
Example 3
Source File: VPackExample.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@Test
public void buildObject() throws VPackException {
	final VPackBuilder builder = new VPackBuilder();
	builder.add(ValueType.OBJECT);// object start
	builder.add("foo", 1); // add field "foo" with value 1
	builder.add("bar", 2); // add field "bar" with value 2
	builder.close();// object end

	final VPackSlice slice = builder.slice(); // create slice
	assertThat(slice.isObject(), is(true));
	assertThat(slice.size(), is(2)); // number of fields

	final VPackSlice foo = slice.get("foo"); // get field "foo"
	assertThat(foo.isInteger(), is(true));
	assertThat(foo.getAsInt(), is(1));

	final VPackSlice bar = slice.get("bar"); // get field "bar"
	assertThat(bar.isInteger(), is(true));
	assertThat(bar.getAsInt(), is(2));

	// iterate over the fields
	for (final Iterator<Entry<String, VPackSlice>> iterator = slice.objectIterator(); iterator.hasNext(); ) {
		final Entry<String, VPackSlice> field = iterator.next();
		assertThat(field.getValue().isInteger(), is(true));
	}
}
 
Example 4
Source File: VPackExample.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@Test
public void buildObjectInObject() throws VPackException {
	final VPackBuilder builder = new VPackBuilder();
	builder.add(ValueType.OBJECT);// object start
	builder.add("foo", ValueType.OBJECT); // add object in field "foo"
	builder.add("bar", 2); // add field "bar" with value 2 to object "foo"
	builder.close();// object "foo" end
	builder.close();// object end

	final VPackSlice slice = builder.slice(); // create slice
	assertThat(slice.isObject(), is(true));

	final VPackSlice foo = slice.get("foo");
	assertThat(foo.isObject(), is(true));

	final VPackSlice bar = foo.get("bar"); // get field "bar" from "foo"
	assertThat(bar.isInteger(), is(true));
}
 
Example 5
Source File: VPackExample.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@Test
public void buildObject() throws VPackException {
    final VPackBuilder builder = new VPackBuilder();
    builder.add(ValueType.OBJECT);// object start
    builder.add("foo", 1); // add field "foo" with value 1
    builder.add("bar", 2); // add field "bar" with value 2
    builder.close();// object end

    final VPackSlice slice = builder.slice(); // create slice
    assertThat(slice.isObject(), is(true));
    assertThat(slice.size(), is(2)); // number of fields

    final VPackSlice foo = slice.get("foo"); // get field "foo"
    assertThat(foo.isInteger(), is(true));
    assertThat(foo.getAsInt(), is(1));

    final VPackSlice bar = slice.get("bar"); // get field "bar"
    assertThat(bar.isInteger(), is(true));
    assertThat(bar.getAsInt(), is(2));

    // iterate over the fields
    for (final Iterator<Entry<String, VPackSlice>> iterator = slice.objectIterator(); iterator.hasNext(); ) {
        final Entry<String, VPackSlice> field = iterator.next();
        assertThat(field.getValue().isInteger(), is(true));
    }
}
 
Example 6
Source File: VPackExample.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@Test
public void buildObjectInObject() throws VPackException {
    final VPackBuilder builder = new VPackBuilder();
    builder.add(ValueType.OBJECT);// object start
    builder.add("foo", ValueType.OBJECT); // add object in field "foo"
    builder.add("bar", 2); // add field "bar" with value 2 to object "foo"
    builder.close();// object "foo" end
    builder.close();// object end

    final VPackSlice slice = builder.slice(); // create slice
    assertThat(slice.isObject(), is(true));

    final VPackSlice foo = slice.get("foo");
    assertThat(foo.isObject(), is(true));

    final VPackSlice bar = foo.get("bar"); // get field "bar" from "foo"
    assertThat(bar.isInteger(), is(true));
}
 
Example 7
Source File: ArangoEntityWriter.java    From spring-data with Apache License 2.0 4 votes vote down vote up
default VPackSlice write(final Object source) {
	final VPackBuilder builder = new VPackBuilder();
	write(source, builder);
	return builder.slice();
}