Fixed input parameters order for services rest api

I’m trying to use both CUBA rest API and swagger-codegen. however, there is a limitation that in CUBA “com.haulmont.restapi.service.ServicesControllerManager#_invokeServiceMethod” check fixed order of input parameter which is deserialized from JSON string as below:


for (int i = 0; i < types.length; i++) {
    try {
        paramValues.add(restParseUtils.toObject(types&#91; i &#93;, paramValuesStr.get(i), modelVersion));
    } catch (Exception e) {
        log.error("Error on parsing service param value", e);
        throw new RestAPIException("Invalid parameter value",
                "Invalid parameter value for " + paramNames.get(i),
                HttpStatus.BAD_REQUEST);
    }
}

Object methodResult;
try {
    methodResult = serviceMethod.invoke(service, paramValues.toArray());
} catch (InvocationTargetException | IllegalAccessException ex) {
    if (ex.getCause() instanceof ValidationException) {
        throw (ValidationException) ex.getCause();
    } else {
        log.error("Error on service method invoke", ex.getCause());
        throw new RestAPIException("Error on service method invoke", "", HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

but according to json spec, you can not expect order of json fields. Additionaly in GSON which is used by swagger-codegen spread entity fields randomly. So code generated by swagger-codegen can not work properly (most of time can not find method exception raising).
I’d like to know the purpose of your design to know if I need to customize swagger-codegen to use Jackson for instance.

Thanks for your time.

Hi Greg,
You are right, we shouldn’t rely on parameters order in JSON. It shouldn’t matter. This will be fixed in next bugfix release of v 6.6. See the related issue.

It’s cool. Thanks a lot!

:ticket: See the following issue in our bug tracker:

https://youtrack.cuba-platform.com/issue/PL-9517