Пример #1
0
  @Test
  public void testWithAllPrimitivesAndString() throws Exception {
    Serializer<Serializable> s = new CompactJavaSerializer(null);

    ClassLoader loaderA = createClassNameRewritingLoader(Foo_A.class);
    Serializable a = (Serializable) loaderA.loadClass(newClassName(Foo_A.class)).newInstance();
    ByteBuffer encodedA = s.serialize(a);

    pushTccl(Foo.class.getClassLoader());
    try {
      Foo foo = (Foo) s.read(encodedA);

      Assert.assertEquals(true, foo.z);
      Assert.assertEquals(5, foo.b);
      Assert.assertEquals('5', foo.c);
      Assert.assertEquals(5, foo.s);
      Assert.assertEquals(5, foo.i);
      Assert.assertEquals(5, foo.j);
      Assert.assertEquals(5, foo.f, 0.0f);
      Assert.assertEquals(5, foo.d, 0.0);
      Assert.assertEquals("5", foo.str);
    } finally {
      popTccl();
    }
  }
Пример #2
0
  @Test
  public void testWithTwoStrings() throws Exception {
    Serializer<Serializable> s = new CompactJavaSerializer(null);

    ClassLoader loaderA = createClassNameRewritingLoader(Bar_A.class);
    Serializable a = (Serializable) loaderA.loadClass(newClassName(Bar_A.class)).newInstance();
    ByteBuffer encodedA = s.serialize(a);

    pushTccl(Bar.class.getClassLoader());
    try {
      Bar bar = (Bar) s.read(encodedA);

      Assert.assertEquals("qwerty", bar.s1);
      Assert.assertEquals("asdfg", bar.s2);
    } finally {
      popTccl();
    }
  }
Пример #3
0
 @Override
 public T read(ByteBuffer binary) throws SerializerException, ClassNotFoundException {
   return serializer.read(binary);
 }