From 2f2de4c0c6b2bd819a56a700f9af80350da74893 Mon Sep 17 00:00:00 2001 From: Maxim Gorbunkov Date: Thu, 5 Jul 2018 11:01:31 +0400 Subject: [PATCH] REST service method invocation fails if the method returns a collection of collections #1025 --- .../restapi/service/ServicesControllerManager.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/rest-api/src/com/haulmont/restapi/service/ServicesControllerManager.java b/modules/rest-api/src/com/haulmont/restapi/service/ServicesControllerManager.java index 6be8f8ed40..601813d6a6 100644 --- a/modules/rest-api/src/com/haulmont/restapi/service/ServicesControllerManager.java +++ b/modules/rest-api/src/com/haulmont/restapi/service/ServicesControllerManager.java @@ -157,8 +157,8 @@ public class ServicesControllerManager { modelVersion, JsonTransformationDirection.TO_VERSION, entityJson); return new ServiceCallResult(entityJson, true); } else if (Collection.class.isAssignableFrom(methodReturnType)) { - Class returnTypeArgument = getMethodReturnTypeArgument(serviceMethod); - if ((returnTypeArgument != null && Entity.class.isAssignableFrom(returnTypeArgument)) + Type returnTypeArgument = getMethodReturnTypeArgument(serviceMethod); + if ((returnTypeArgument instanceof Class && Entity.class.isAssignableFrom((Class) returnTypeArgument)) || isEntitiesCollection((Collection) methodResult)) { Collection entities = (Collection) methodResult; entities.forEach(entity -> restControllerUtils.applyAttributesSecurity(entity)); @@ -166,7 +166,7 @@ public class ServicesControllerManager { null, EntitySerializationOption.SERIALIZE_INSTANCE_NAME); if (returnTypeArgument != null) { - MetaClass metaClass = metadata.getClass(returnTypeArgument); + MetaClass metaClass = metadata.getClass((Class) returnTypeArgument); if (metaClass != null) { entitiesJson = restControllerUtils.transformJsonIfRequired(metaClass.getName(), modelVersion, JsonTransformationDirection.TO_VERSION, entitiesJson); @@ -189,13 +189,13 @@ public class ServicesControllerManager { } @Nullable - protected Class getMethodReturnTypeArgument(Method serviceMethod) { - Class returnTypeArgument = null; + protected Type getMethodReturnTypeArgument(Method serviceMethod) { + Type returnTypeArgument = null; Type genericReturnType = serviceMethod.getGenericReturnType(); if (genericReturnType instanceof ParameterizedType) { Type[] actualTypeArguments = ((ParameterizedType) genericReturnType).getActualTypeArguments(); if (actualTypeArguments.length > 0) { - returnTypeArgument = (Class) actualTypeArguments[0]; + returnTypeArgument = actualTypeArguments[0]; } } return returnTypeArgument;