|
21 | 21 | package com.arangodb.velocypack; |
22 | 22 |
|
23 | 23 | import static org.hamcrest.Matchers.is; |
| 24 | +import static org.hamcrest.Matchers.contains; |
24 | 25 | import static org.hamcrest.Matchers.notNullValue; |
25 | 26 | import static org.hamcrest.Matchers.nullValue; |
26 | 27 | import static org.junit.Assert.assertThat; |
@@ -981,7 +982,83 @@ public void toArrayInArray() throws VPackException { |
981 | 982 | } |
982 | 983 | } |
983 | 984 |
|
| 985 | + protected static class TestCollection extends LinkedList<String> { |
| 986 | + |
| 987 | + } |
| 988 | + |
| 989 | + protected static class TestEntityCollectionExtendedWithNulls { |
| 990 | + |
| 991 | + protected TestCollection a1; |
| 992 | + |
| 993 | + public TestCollection getA1() { |
| 994 | + return a1; |
| 995 | + } |
| 996 | + |
| 997 | + public void setA1(final TestCollection a1) { |
| 998 | + this.a1 = a1; |
| 999 | + } |
| 1000 | + |
| 1001 | + } |
| 1002 | + |
| 1003 | + @Test |
| 1004 | + public void fromCollectionExtendedWithNulls() throws Exception { |
| 1005 | + |
| 1006 | + final TestCollection collection = new TestCollection(); |
| 1007 | + collection.add("one"); |
| 1008 | + collection.add(null); |
| 1009 | + collection.add("two"); |
| 1010 | + |
| 1011 | + final TestEntityCollectionExtendedWithNulls entity = new TestEntityCollectionExtendedWithNulls(); |
| 1012 | + entity.setA1(collection); |
| 1013 | + |
| 1014 | + final VPackSlice vpack = new VPack.Builder() |
| 1015 | + .serializeNullValues(true) |
| 1016 | + .build() |
| 1017 | + .serialize(entity); |
| 1018 | + assertThat(vpack, is(notNullValue())); |
| 1019 | + assertThat(vpack.isObject(), is(true)); |
| 1020 | + { |
| 1021 | + final VPackSlice a1 = vpack.get("a1"); |
| 1022 | + assertThat(a1.isArray(), is(true)); |
| 1023 | + assertThat(a1.getLength(), is(entity.a1.size())); |
| 1024 | + |
| 1025 | + VPackSlice at = a1.get(0); |
| 1026 | + assertThat(at.isString(), is(true)); |
| 1027 | + assertThat(at.getAsString(), is(entity.a1.get(0))); |
| 1028 | + at = a1.get(1); |
| 1029 | + assertThat(at.isNull(), is(true)); |
| 1030 | + at = a1.get(2); |
| 1031 | + assertThat(at.isString(), is(true)); |
| 1032 | + assertThat(at.getAsString(), is(entity.a1.get(2))); |
| 1033 | + } |
| 1034 | + } |
| 1035 | + |
| 1036 | + @Test |
| 1037 | + public void toCollectionExtendedWithNulls() throws Exception { |
| 1038 | + final VPackBuilder builder = new VPackBuilder(); |
| 1039 | + { |
| 1040 | + builder.add(ValueType.OBJECT); |
| 1041 | + { |
| 1042 | + builder.add("a1", ValueType.ARRAY); |
| 1043 | + builder.add("one"); |
| 1044 | + builder.add(ValueType.NULL); |
| 1045 | + builder.add("two"); |
| 1046 | + builder.close(); |
| 1047 | + } |
| 1048 | + builder.close(); |
| 1049 | + } |
| 1050 | + |
| 1051 | + final VPackSlice vpack = builder.slice(); |
| 1052 | + final TestEntityCollectionExtendedWithNulls entity = new VPack.Builder() |
| 1053 | + .build().deserialize(vpack, TestEntityCollectionExtendedWithNulls.class); |
| 1054 | + assertThat(entity, is(notNullValue())); |
| 1055 | + assertThat(entity.getA1(), is(notNullValue())); |
| 1056 | + assertThat(entity.getA1().size(), is(3)); |
| 1057 | + assertThat(entity.getA1(), contains("one", null, "two")); |
| 1058 | + } |
| 1059 | + |
984 | 1060 | protected static class TestEntityArrayInArrayInArray { |
| 1061 | + |
985 | 1062 | private double[][][] a1; |
986 | 1063 |
|
987 | 1064 | public double[][][] getA1() { |
|
0 commit comments