Search in sources :

Example 1 with Organization

use of org.apache.dubbo.common.serialize.model.Organization 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 2 with Organization

use of org.apache.dubbo.common.serialize.model.Organization in project dubbo-spi-extensions 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 3 with Organization

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

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)

Aggregations

StringReader (java.io.StringReader)3 Method (java.lang.reflect.Method)3 Type (java.lang.reflect.Type)3 List (java.util.List)3 Organization (org.apache.dubbo.common.serialize.model.Organization)3 Person (org.apache.dubbo.common.serialize.model.Person)3 Test (org.junit.jupiter.api.Test)3