public static GetFields_Result getFields(Database database, GetFields_Param params) throws APIException {
        
        Logger.getLogger(API.class.getName()).log(Level.FINE, "Entering API.getFields()");
        GetFields_Result result;
        try { // Validate User
            ValidateUser_Result vResult = validateUser(database, new ValidateUser_Param(params.username(), params.password()));
            if (vResult == null || !vResult.validated()) { // not validated
                result = null;
            }
            else { // User exists
                int projectId;

                // If the project ID is a String (It is an Object in params)
                if (String.class == params.projectId().getClass()) {
                    String projectParam = (String) params.projectId();
                    if (projectParam.isEmpty()) { // And it is empty
                        projectId = 0;
                    }
                    else { // And it is not empty, it is invalid.
                        APIException ex = new APIException("Project ID parameter is invalid.");
                        Logger.getLogger(API.class.getName()).log(Level.WARNING, "String Project ID must be empty.", ex);
                        throw ex;
                    }
                } // If the project ID is not a String or an Integer, it is invalid.
                else if (Integer.class != params.projectId().getClass()) {
                    APIException ex = new APIException("Project ID parameter is invalid.");
                    Logger.getLogger(API.class.getName()).log(Level.WARNING, "Project ID must be empty String or Integer", ex);
                    throw ex;
                }
                else { // If it is an Integer, get the int value.
                    projectId = ((Integer) params.projectId()).intValue();
                }

                // Get Fields with the right project ID (or all Fields if
                // params.projectID is an empty String)
                Field tField = new Field();
                tField.setProjectId(projectId);
                ArrayList<Field> fields = (ArrayList) database.get(tField);
                
                if (fields.isEmpty()) { // If there are no Fields for this project
                    result = null; // Fail
                }
                else { // If there are Fields for this Project
                    // Get IDs and Titles out of the Fields
                    ArrayList<Integer> projectIds = new ArrayList<>();
                    ArrayList<Integer> fieldIds = new ArrayList<>();
                    ArrayList<String> fieldTitles = new ArrayList<>();
                    for (Field field : fields) {
                        projectIds.add(new Integer(field.projectId()));
                        fieldIds.add(new Integer(field.fieldId()));
                        fieldTitles.add(field.title());
                    }
                    if (fieldIds.size() != fieldTitles.size()) {
                        result = null;
                    }
                    else {
                        result = new GetFields_Result(projectIds, fieldIds, fieldTitles);
                    }
                }
            }
        }
        catch (DatabaseException | GetFailedException | GetFields_Result.GetFields_ResultException ex) {
            result = null;
            Logger.getLogger(API.class.getName()).log(Level.WARNING, "getFields request failed.", ex);
        }
        Logger.getLogger(API.class.getName()).log(Level.FINE, "Exiting API.getFields()");
        return result;
        
    }