Search in sources :

Example 1 with Person

use of org.apache.dubbo.common.serialize.model.Person in project dubbo by alibaba.

the class AbstractSerializationPersonFailTest method test_IntPersonMap.

@Test
public void test_IntPersonMap() throws Exception {
    Map<Integer, Person> args = new HashMap<Integer, Person>();
    args.put(1, new Person());
    try {
        ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
        objectOutput.writeObject(args);
        fail();
    } catch (NotSerializableException expected) {
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString(FAIL_STRING));
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) ObjectOutput(org.apache.dubbo.common.serialize.ObjectOutput) HashMap(java.util.HashMap) Person(org.apache.dubbo.common.serialize.model.Person) Test(org.junit.jupiter.api.Test)

Example 2 with Person

use of org.apache.dubbo.common.serialize.model.Person in project dubbo by alibaba.

the class AbstractSerializationPersonFailTest method test_PersonList.

@Test
public void test_PersonList() throws Exception {
    List<Person> args = new ArrayList<Person>();
    args.add(new Person());
    try {
        ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
        objectOutput.writeObject(args);
        fail();
    } catch (NotSerializableException expected) {
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString(FAIL_STRING));
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) ObjectOutput(org.apache.dubbo.common.serialize.ObjectOutput) ArrayList(java.util.ArrayList) Person(org.apache.dubbo.common.serialize.model.Person) Test(org.junit.jupiter.api.Test)

Example 3 with Person

use of org.apache.dubbo.common.serialize.model.Person in project dubbo by alibaba.

the class AbstractSerializationPersonFailTest method test_StringPersonMap.

@Test
public void test_StringPersonMap() throws Exception {
    Map<String, Person> args = new HashMap<String, Person>();
    args.put("1", new Person());
    try {
        ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
        objectOutput.writeObject(args);
        fail();
    } catch (NotSerializableException expected) {
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString(FAIL_STRING));
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) ObjectOutput(org.apache.dubbo.common.serialize.ObjectOutput) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) Person(org.apache.dubbo.common.serialize.model.Person) Test(org.junit.jupiter.api.Test)

Example 4 with Person

use of org.apache.dubbo.common.serialize.model.Person in project dubbo by alibaba.

the class FastJsonObjectInputTest method testReadObjectWithTowType.

@Test
public void testReadObjectWithTowType() throws Exception {
    fastJsonObjectInput = new FastJsonObjectInput(new StringReader("[{\"name\":\"John\",\"age\":30},{\"name\":\"Born\",\"age\":24}]"));
    Method methodReturnType = getClass().getMethod("towLayer");
    Type type = methodReturnType.getGenericReturnType();
    List<Person> o = fastJsonObjectInput.readObject(List.class, type);
    assertTrue(o instanceof List);
    assertTrue(o.get(0) instanceof Person);
    assertThat(o.size(), is(2));
    assertThat(o.get(1).getName(), is("Born"));
}
Also used : Type(java.lang.reflect.Type) StringReader(java.io.StringReader) List(java.util.List) Method(java.lang.reflect.Method) Person(org.apache.dubbo.common.serialize.model.Person) Test(org.junit.jupiter.api.Test)

Example 5 with Person

use of org.apache.dubbo.common.serialize.model.Person in project dubbo by alibaba.

the class AvroObjectInputOutputTest method testWriteReadObjectWithoutClass.

@Test
public void testWriteReadObjectWithoutClass() throws IOException, ClassNotFoundException {
    Person p = new Person();
    p.setAge(30);
    p.setName("abc");
    avroObjectOutput.writeObject(p);
    avroObjectOutput.flushBuffer();
    pos.close();
    // 这里会丢失所有信息
    Object result = avroObjectInput.readObject();
    assertThat(result, not(nullValue()));
// assertThat(result.getName(), is("abc"));
// assertThat(result.getAge(), is(30));
}
Also used : Person(org.apache.dubbo.common.serialize.model.Person) Test(org.junit.jupiter.api.Test)

Aggregations

Person (org.apache.dubbo.common.serialize.model.Person)12 Test (org.junit.jupiter.api.Test)12 NotSerializableException (java.io.NotSerializableException)7 ObjectOutput (org.apache.dubbo.common.serialize.ObjectOutput)7 List (java.util.List)4 StringReader (java.io.StringReader)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Method (java.lang.reflect.Method)2 Type (java.lang.reflect.Type)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 HashSet (java.util.HashSet)1 Organization (org.apache.dubbo.common.serialize.model.Organization)1