Search in sources :

Example 1 with NoSuchParserException

use of ratpack.parse.NoSuchParserException in project ratpack by ratpack.

the class DefaultContext method parse.

@Override
public <T, O> T parse(TypedData body, Parse<T, O> parse) throws Exception {
    Function<Parser<?>, T> parserPredicate;
    List<Parser<?>> parsers = Lists.newArrayList();
    if (parse.getOpts().isPresent()) {
        parserPredicate = parser -> {
            if (parser.getOptsType().isInstance(parse.getOpts().get())) {
                parsers.add(parser);
                Parser<O> cast = Types.cast(parser);
                return cast.parse(DefaultContext.this, body, parse);
            }
            return null;
        };
    } else {
        parserPredicate = parser -> {
            parsers.add(parser);
            Parser<O> cast = Types.cast(parser);
            return cast.parse(DefaultContext.this, body, parse);
        };
    }
    return joinedRegistry.first(PARSER_TYPE_TOKEN, parserPredicate).orElseThrow(() -> new NoSuchParserException(parse.getType(), parse.getOpts().orElse(null), body.getContentType().getType(), parsers));
}
Also used : NoSuchParserException(ratpack.parse.NoSuchParserException) Parser(ratpack.parse.Parser)

Aggregations

NoSuchParserException (ratpack.parse.NoSuchParserException)1 Parser (ratpack.parse.Parser)1