Search in sources :

Example 11 with SerializedName

use of com.google.gson.annotations.SerializedName in project cloudstack by apache.

the class ApiDiscoveryServiceImpl method getFieldResponseMap.

private ApiResponseResponse getFieldResponseMap(Field responseField) {
    ApiResponseResponse responseResponse = new ApiResponseResponse();
    SerializedName serializedName = responseField.getAnnotation(SerializedName.class);
    Param param = responseField.getAnnotation(Param.class);
    if (serializedName != null && param != null) {
        responseResponse.setName(serializedName.value());
        responseResponse.setDescription(param.description());
        responseResponse.setType(responseField.getType().getSimpleName().toLowerCase());
        // If response is not of primitive type - we have a nested entity
        Class fieldClass = param.responseObject();
        if (fieldClass != null) {
            Class<?> superClass = fieldClass.getSuperclass();
            if (superClass != null) {
                String superName = superClass.getName();
                if (superName.equals(BaseResponse.class.getName())) {
                    Field[] fields = fieldClass.getDeclaredFields();
                    for (Field field : fields) {
                        ApiResponseResponse innerResponse = getFieldResponseMap(field);
                        if (innerResponse != null) {
                            responseResponse.addApiResponse(innerResponse);
                        }
                    }
                }
            }
        }
    }
    return responseResponse;
}
Also used : BaseResponse(org.apache.cloudstack.api.BaseResponse) Field(java.lang.reflect.Field) ApiResponseResponse(org.apache.cloudstack.api.response.ApiResponseResponse) SerializedName(com.google.gson.annotations.SerializedName) Param(com.cloud.serializer.Param)

Aggregations

SerializedName (com.google.gson.annotations.SerializedName)11 Field (java.lang.reflect.Field)9 Param (com.cloud.serializer.Param)6 ArrayList (java.util.ArrayList)4 BaseResponse (com.cloud.api.BaseResponse)2 Account (com.cloud.user.Account)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 ExceptionProxyObject (com.cloud.utils.exception.ExceptionProxyObject)2 Collection (java.util.Collection)2 Date (java.util.Date)2 BaseResponse (org.apache.cloudstack.api.BaseResponse)2 AsyncJobResponse (org.apache.cloudstack.api.response.AsyncJobResponse)2 RoleType (com.cloud.acl.RoleType)1 ResponseObject (com.cloud.api.ResponseObject)1 ApiResponseResponse (com.cloud.api.response.ApiResponseResponse)1 AsyncJobResponse (com.cloud.api.response.AsyncJobResponse)1 KubernetesType (io.kubernetes.client.common.KubernetesType)1 IntOrString (io.kubernetes.client.custom.IntOrString)1 Quantity (io.kubernetes.client.custom.Quantity)1 V1Container (io.kubernetes.client.openapi.models.V1Container)1