public abstract class NoOptParserSupport extends ParserSupport<NullParseOpts>
The following is an example of an implementation that parses to an Integer
.
import ratpack.parse.NullParseOpts; import ratpack.parse.NoOptParserSupport; import ratpack.http.TypedData; import ratpack.handling.Context; import ratpack.handling.Handler; public class IntParser extends NoOptParserSupport { public IntParser() { super("text/plain"); } public <T> T parse(Context context, TypedData body, Class<T> type) { return type.cast(Integer.valueOf(body.getText())); } } public class ExampleHandler implements Handler { public void handle(Context context) { // assuming IntParser has been registered upstream Integer integer = context.parse(Integer.class); // … } }
Modifier | Constructor and Description |
---|---|
protected |
NoOptParserSupport(String contentType)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected abstract <T> T |
parse(Context context,
TypedData requestBody,
Class<T> type)
The parser implementation.
|
<T> T |
parse(Context context,
TypedData requestBody,
Parse<T,NullParseOpts> parse)
Delegates to
parse(ratpack.handling.Context, ratpack.http.TypedData, Class) , discarding the opts object of the given parse . |
getContentType, getOptsType
protected NoOptParserSupport(String contentType)
contentType
- the type of request this parser can handlepublic final <T> T parse(Context context, TypedData requestBody, Parse<T,NullParseOpts> parse) throws Exception
parse(ratpack.handling.Context, ratpack.http.TypedData, Class)
, discarding the
opts object of the given parse
.T
- the type of object to construct from the request bodycontext
- The context to deserializerequestBody
- The request body to deserializeparse
- The description of how to parse the request bodyparse(ratpack.handling.Context, ratpack.http.TypedData, Class)
Exception
- any exception thrown by parse(ratpack.handling.Context, ratpack.http.TypedData, Class)
protected abstract <T> T parse(Context context, TypedData requestBody, Class<T> type) throws Exception
T
- the type of object to construct from the request bodycontext
- The context to deserializerequestBody
- The request body to deserializetype
- the type of object to construct from the request bodyT
if this parser can construct this type, otherwise null
Exception
- any exception thrown while parsing