All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.dropwizard.jersey.params.BooleanParam Maven / Gradle / Ivy

There is a newer version: 5.0.0-rc.1
Show newest version
package io.dropwizard.jersey.params;

import javax.annotation.Nullable;

/**
 * A parameter encapsulating boolean values. If the query parameter value is {@code "true"},
 * regardless of case, the returned value is {@link Boolean#TRUE}. If the query parameter value is
 * {@code "false"}, regardless of case, the returned value is {@link Boolean#FALSE}. All other
 * values will return a {@code 400 Bad Request} response.
 */
public class BooleanParam extends AbstractParam {
    public BooleanParam(@Nullable String input) {
        super(input);
    }

    public BooleanParam(@Nullable String input, String parameterName) {
        super(input, parameterName);
    }

    @Override
    protected String errorMessage(Exception e) {
        return "%s must be \"true\" or \"false\".";
    }

    @Override
    protected Boolean parse(@Nullable String input) throws Exception {
        if ("true".equalsIgnoreCase(input)) {
            return Boolean.TRUE;
        }
        if ("false".equalsIgnoreCase(input)) {
            return Boolean.FALSE;
        }
        throw new Exception();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy