Search in sources :

Example 11 with Person

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

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 12 with Person

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

the class FastJsonObjectInputTest method testReadObjectWithThreeType.

@Test
public void testReadObjectWithThreeType() throws Exception {
    fastJsonObjectInput = new FastJsonObjectInput(new StringReader("{\"data\":[{\"name\":\"John\",\"age\":30},{\"name\":\"Born\",\"age\":24}]}"));
    Method methodReturnType = getClass().getMethod("threeLayer");
    Type type = methodReturnType.getGenericReturnType();
    Organization<List<Person>> o = fastJsonObjectInput.readObject(Organization.class, type);
    assertTrue(o instanceof Organization);
    assertTrue(o.getData() instanceof List);
    assertTrue(o.getData().get(0) instanceof Person);
    assertThat(o.getData().size(), is(2));
    assertThat(o.getData().get(1).getName(), is("Born"));
}
Also used : Type(java.lang.reflect.Type) Organization(org.apache.dubbo.common.serialize.model.Organization) 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 13 with Person

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

the class FastJsonObjectInputTest method testReadObject.

@Test
public void testReadObject() throws IOException, ClassNotFoundException {
    fastJsonObjectInput = new FastJsonObjectInput(new StringReader("{ \"name\":\"John\", \"age\":30 }"));
    Person result = fastJsonObjectInput.readObject(Person.class);
    assertThat(result, not(nullValue()));
    assertThat(result.getName(), is("John"));
    assertThat(result.getAge(), is(30));
}
Also used : StringReader(java.io.StringReader) Person(org.apache.dubbo.common.serialize.model.Person) Test(org.junit.jupiter.api.Test)

Example 14 with Person

use of org.apache.dubbo.common.serialize.model.Person in project dubbo-spi-extensions by apache.

the class AbstractSerializationPersonFailTest method test_Person.

@Test
public void test_Person() throws Exception {
    try {
        ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
        objectOutput.writeObject(new Person());
        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) Person(org.apache.dubbo.common.serialize.model.Person) Test(org.junit.jupiter.api.Test)

Example 15 with Person

use of org.apache.dubbo.common.serialize.model.Person in project dubbo-spi-extensions by apache.

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) Person(org.apache.dubbo.common.serialize.model.Person) Test(org.junit.jupiter.api.Test)

Aggregations

Person (org.apache.dubbo.common.serialize.model.Person)36 Test (org.junit.jupiter.api.Test)36 NotSerializableException (java.io.NotSerializableException)21 ObjectOutput (org.apache.dubbo.common.serialize.ObjectOutput)21 List (java.util.List)10 StringReader (java.io.StringReader)9 Method (java.lang.reflect.Method)6 Type (java.lang.reflect.Type)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 Organization (org.apache.dubbo.common.serialize.model.Organization)3 HashSet (java.util.HashSet)2