Exemple #1
0
 @Test
 public void testPrimitiveArray() throws IOException {
   DslJson<Object> json = new DslJson<Object>();
   JsonWriter writer = new JsonWriter();
   int[] items = new int[] {1, 2};
   json.serialize(writer, items);
   String result = writer.toString();
   Assert.assertEquals("[1,2]", result);
   int[] deserialized = json.deserialize(int[].class, writer.getByteBuffer(), writer.size());
   Assert.assertArrayEquals(items, deserialized);
 }
Exemple #2
0
 @Ignore("not supported yet")
 @Test
 public void testNestedArray() throws IOException {
   DslJson<Object> json = new DslJson<Object>();
   JsonWriter writer = new JsonWriter();
   int[][] items = new int[2][];
   items[0] = new int[] {1, 2};
   items[1] = new int[] {3, 4, 5};
   json.serialize(writer, items);
   String result = writer.toString();
   Assert.assertEquals("[[1,2],[3,4,5]]", result);
   int[][] deserialized = json.deserialize(int[][].class, writer.getByteBuffer(), writer.size());
   Assert.assertArrayEquals(items, deserialized);
 }
Exemple #3
0
 @Test
 public void testListGenerics() throws IOException {
   DslJson<Object> json = new DslJson<Object>();
   JsonWriter writer = new JsonWriter();
   List<Integer> items = Arrays.asList(1, 2);
   json.serialize(writer, items);
   String result = writer.toString();
   Assert.assertEquals("[1,2]", result);
   List<Integer> deserialized =
       (List)
           json.deserialize(
               new Generic<List<Integer>>() {}.type, writer.getByteBuffer(), writer.size());
   Assert.assertEquals(items, deserialized);
 }