Skip to content

Commit 28b11a4

Browse files
author
Mark
committed
fixed VPack serializing of array with null values (issue #88)
1 parent 9c81702 commit 28b11a4

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

ChangeLog

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
v4.1.5 (2016-01-xx)
1+
v4.1.5 (2017-01-xx)
22
---------------------------
33
* fixed VPack parsing of fields of type Object
4+
* fixed VPack serializing of array with null values (issue #88)
45

56
v4.1.4 (2016-12-19)
67
---------------------------

src/main/java/com/arangodb/velocypack/VPack.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,9 @@ private void serializeArray(
579579
builder.add(name, ValueType.ARRAY);
580580
for (int i = 0; i < Array.getLength(value); i++) {
581581
final Object element = Array.get(value, i);
582-
addValue(null, element.getClass(), element, builder, null, additionalFields);
582+
if (element != null) {
583+
addValue(null, element.getClass(), element, builder, null, additionalFields);
584+
}
583585
}
584586
builder.close();
585587
}

src/test/java/com/arangodb/velocypack/VPackSerializeDeserializeTest.java

+16
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,22 @@ public void toArray() throws VPackException {
677677
}
678678
}
679679

680+
@Test
681+
public void fromArrayWithNull() {
682+
final TestEntityArray entity = new TestEntityArray();
683+
entity.a1 = new String[] { "foo", null };
684+
685+
final VPackSlice vpack = new VPack.Builder().build().serialize(entity);
686+
assertThat(vpack, is(notNullValue()));
687+
assertThat(vpack.isObject(), is(true));
688+
689+
final VPackSlice a1 = vpack.get("a1");
690+
assertThat(a1.isArray(), is(true));
691+
assertThat(a1.size(), is(1));
692+
assertThat(a1.get(0).isString(), is(true));
693+
assertThat(a1.get(0).getAsString(), is("foo"));
694+
}
695+
680696
protected enum TestEnum {
681697
A, B, C
682698
}

0 commit comments

Comments
 (0)