* ]
* }
*
*/
MapVector v = new MapVector("", allocator);
ComplexWriterImpl writer = new ComplexWriterImpl("col", v);
writer.allocate();
{
MapWriter map = writer.rootAsMap();
ListWriter list = map.list("a");
list.start();
ListWriter innerList = list.list();
IntWriter innerInt = innerList.integer();
innerList.start();
IntHolder holder = new IntHolder();
holder.value = 1;
innerInt.write(holder);
holder.value = 2;
innerInt.write(holder);
holder.value = 3;
innerInt.write(holder);
innerList.end();
innerList.start();
holder.value = 4;
innerInt.write(holder);
holder.value = 5;
innerInt.write(holder);
innerList.end();
list.end();
IntWriter numCol = map.integer("nums");
holder.value = 14;
numCol.write(holder);
MapWriter repeatedMap = map.list("b").map();
repeatedMap.start();
holder.value = 1;
repeatedMap.integer("c").write(holder);
repeatedMap.end();
repeatedMap.start();
holder.value = 2;
repeatedMap.integer("c").write(holder);
BigIntHolder h = new BigIntHolder();
h.value = 15;
repeatedMap.bigInt("x").write(h);
repeatedMap.end();
map.end();
}
assert writer.ok();
{
writer.setPosition(1);
MapWriter map = writer.rootAsMap();
ListWriter list = map.list("a");
list.start();
ListWriter innerList = list.list();
IntWriter innerInt = innerList.integer();
innerList.start();
IntHolder holder = new IntHolder();
holder.value = -1;
innerInt.write(holder);
holder.value = -2;
innerInt.write(holder);
holder.value = -3;
innerInt.write(holder);
innerList.end();
innerList.start();
holder.value = -4;
innerInt.write(holder);
holder.value = -5;
innerInt.write(holder);
innerList.end();
list.end();
IntWriter numCol = map.integer("nums");
holder.value = -28;
numCol.write(holder);
MapWriter repeatedMap = map.list("b").map();
repeatedMap.start();
holder.value = -1;
repeatedMap.integer("c").write(holder);
repeatedMap.end();
repeatedMap.start();
holder.value = -2;
repeatedMap.integer("c").write(holder);
BigIntHolder h = new BigIntHolder();
h.value = -30;
repeatedMap.bigInt("x").write(h);
repeatedMap.end();
map.end();
}
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
System.out.println("Map of Object[0]: " + ow.writeValueAsString(v.getAccessor().getObject(0)));
System.out.println("Map of Object[1]: " + ow.writeValueAsString(v.getAccessor().getObject(1)));
ByteArrayOutputStream stream = new ByteArrayOutputStream();
JsonWriter jsonWriter = new JsonWriter(stream, true);
FieldReader reader = v.get("col", MapVector.class).getAccessor().getReader();
reader.setPosition(0);
jsonWriter.write(reader);
reader.setPosition(1);
jsonWriter.write(reader);
System.out.print("Json Read: ");