public interface Parser
There are two ways of registering a parser:
Jooby.parser(Parser)
methodMultibinder<Parser> pcb = Multibinder .newSetBinder(binder, Parser.class); pcb.addBinding().to(MyParser.class);
Date
: It parses a date using the application.dateFormat
property.LocalDate
: It parses a date using the application.dateFormat
property.Locale
valueOf
fromName
fromString
String
argumentJooby.parser(Parser)
Modifier and Type | Interface and Description |
---|---|
static interface |
Parser.BodyReference
Expose the HTTP body as a series of bytes or text.
|
static interface |
Parser.Builder
A parser can be executed against a simply HTTP param, a set of HTTP params, an file
Upload or HTTP Parser.BodyReference . |
static interface |
Parser.Callback<T>
A parser callback.
|
static interface |
Parser.Context
Allows you to access to parsing strategies, content type view
Parser.Context.type() and invoke next
parser in the chain via Parser.Context.next() methods. |
static interface |
Parser.ParamReference<T>
Expose HTTP params from path, query, form url encoded or multipart request as a raw string.
|
Modifier and Type | Method and Description |
---|---|
Object |
parse(com.google.inject.TypeLiteral<?> type,
Parser.Context ctx)
Parse one or more values to the required type.
|
Object parse(com.google.inject.TypeLiteral<?> type, Parser.Context ctx) throws Exception
Parse one or more values to the required type. If the parser doesn't support the required type
a call to Parser.Context.next(TypeLiteral, Object)
must be done.
Parser converter = (type, ctx) -> { if (type.getRawType() == MyType.class) { // convert to MyType return ...; } // no luck! move next return next.next(); }It's also possible to create generic/parameterized types too:
public class MyContainerType<T> {} ParamConverter converter = (type, ctx) -> { if (type.getRawType() == MyContainerType.class) { // Creates a new type from current generic type TypeLiterale<?> paramType = TypeLiteral .get(((ParameterizedType) toType.getType()).getActualTypeArguments()[0]); // Ask param converter to resolve the new/next type. Object result = next.next(paramType); return new MyType(result); } // no luck! move next return ctx.next(); }
type
- Requested type.ctx
- Execution context.Exception
- If conversion fails.Copyright © 2015. All rights reserved.