Search in sources :

Example 1 with ParserException

use of io.crnk.core.engine.parser.ParserException in project crnk-framework by crnk-project.

the class DefaultQuerySpecDeserializer method deserializeFilter.

protected void deserializeFilter(QuerySpec querySpec, Parameter parameter) {
    Class<?> attributeType = getAttributeType(querySpec, parameter.attributePath);
    Set<Object> typedValues = new HashSet<>();
    for (String stringValue : parameter.values) {
        try {
            @SuppressWarnings({ "unchecked", "rawtypes" }) Object value = typeParser.parse(stringValue, (Class) attributeType);
            typedValues.add(value);
        } catch (ParserException e) {
            if (ignoreParseExceptions) {
                typedValues.add(stringValue);
                LOGGER.debug("failed to parse {}", parameter);
            } else {
                throw new ParametersDeserializationException(parameter.toString(), e);
            }
        }
    }
    Object value = typedValues.size() == 1 ? typedValues.iterator().next() : typedValues;
    querySpec.addFilter(new FilterSpec(parameter.attributePath, parameter.operator, value));
}
Also used : ParserException(io.crnk.core.engine.parser.ParserException) ParametersDeserializationException(io.crnk.core.exception.ParametersDeserializationException) HashSet(java.util.HashSet)

Aggregations

ParserException (io.crnk.core.engine.parser.ParserException)1 ParametersDeserializationException (io.crnk.core.exception.ParametersDeserializationException)1 HashSet (java.util.HashSet)1