Ejemplo n.º 1
0
 @Test
 public void checkType() throws IOException {
   List<Type> types =
       Arrays.asList(
           int.class,
           int[].class,
           JsonFull.class,
           JsonFull[].class,
           new Generic<List<Integer>>() {}.type,
           new Generic<Integer[]>() {}.type,
           new Generic<List<JsonFull>>() {}.type,
           new Generic<JsonFull[]>() {}.type);
   DslJson<Object> json = new DslJson<Object>();
   for (Type t : types) {
     Assert.assertTrue(json.canSerialize(t));
     Assert.assertTrue(json.canDeserialize(t));
   }
   Assert.assertTrue(json.canSerialize(JsonPartial.class));
   Assert.assertTrue(json.canSerialize(new Generic<List<JsonPartial>>() {}.type));
   Assert.assertFalse(json.canDeserialize(JsonPartial.class));
   Assert.assertFalse(json.canDeserialize(new Generic<List<JsonPartial>>() {}.type));
   // TODO: not supported yet
   Assert.assertFalse(json.canSerialize(int[][].class));
   Assert.assertFalse(json.canDeserialize(int[][].class));
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
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);
 }