@Test
public void gsonTest2() throws NoSuchMethodException {
Method m = What.class.getDeclaredMethod("getRoom");
Type returnType = m.getGenericReturnType();
print(returnType);
ParameterizedType actualType = (ParameterizedType) returnType;
Type[] args = actualType.getActualTypeArguments();
print(args[0]);
print(args[1]);
Room<User, Dog> room = getRoom(28);
Gson gson = new Gson();
String jsonStr = gson.toJson(room);
Room<User, Dog> room2 = gson.fromJson(jsonStr, returnType);
print(room2);
}
@Test
public void gsonTest3() throws NoSuchMethodException {
Method m = What.class.getDeclaredMethod("getRoomList");
Type returnType = m.getGenericReturnType();
print(returnType);
ParameterizedType actualType = (ParameterizedType) returnType;
Type[] args = actualType.getActualTypeArguments();
print(args[0]);
args = ((ParameterizedType) args[0]).getActualTypeArguments();
print(args[0]);
print(args[1]);
}
@Test
public void gsonTest4() throws NoSuchMethodException {
Method m = What.class.getDeclaredMethod("getRoomArray");
Type returnType = m.getGenericReturnType();
print(returnType);
GenericArrayType actualType = (GenericArrayType) returnType;
Type eleType = actualType.getGenericComponentType();
print(eleType);
Type[] args = ((ParameterizedType) eleType).getActualTypeArguments();
print(args[0]);
print(args[1]);
}