T - the type of object to parse topublic abstract class NoOptParserSupport<T> extends Object implements NoOptParser<T>
NoOptParser implementations.
The following is an example of an implementation that parses to an Integer.
import ratpack.parse.NoOptParse;
import ratpack.parse.NoOptParserSupport;
import ratpack.http.TypedData;
import ratpack.handling.Context;
import ratpack.handling.Handler;
public class IntParser extends NoOptParserSupport<Integer> {
public IntParser() {
super("text/plain");
}
public Integer parse(Context context, TypedData body, NoOptParse<Integer> parse) {
return 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 |
|---|---|
String |
getContentType()
The content type that this parser knows how to deserialize.
|
Class<T> |
getParsedType()
The type that this parser can deserialize to.
|
Class<NoOptParse<T>> |
getParseType()
The type of the
Parse object for this parser. |
protected NoOptParserSupport(String contentType)
contentType - the type of request this parser can handlepublic String getContentType()
getContentType in interface Parser<T,NoOptParse<T>>public Class<NoOptParse<T>> getParseType()
Parse object for this parser.getParseType in interface Parser<T,NoOptParse<T>>Parse object for this parser.public Class<T> getParsedType()
getParsedType in interface Parser<T,NoOptParse<T>>