@@ -65,6 +65,16 @@ public interface Parser {
6565 */
6666 List <MediaType > types ();
6767
68+ /**
69+ * Test if the HTTP request body or parameter can be converted to the given type.
70+ *
71+ * @param type The candidate Type.
72+ * @return True if the converter can read the HTTP request body.
73+ */
74+ default boolean canParse (@ Nonnull final Class <?> type ) {
75+ return canParse (TypeLiteral .get (type ));
76+ }
77+
6878 /**
6979 * Test if the HTTP request body or parameter can be converted to the given type.
7080 *
@@ -73,6 +83,31 @@ public interface Parser {
7383 */
7484 boolean canParse (@ Nonnull TypeLiteral <?> type );
7585
86+ /**
87+ * Attempt to read a message from HTTP request body.
88+ * <p>
89+ * For text format (json, yaml, xml, etc.) a converter usually call to
90+ * {@link Body.Reader#text(Body.Reader.Text)} in order to apply correct charset and close
91+ * resources.
92+ * </p>
93+ *
94+ * <p>
95+ * For binary format a converter usually call to {@link Body.Reader#bytes(Body.Reader.Bytes)}
96+ * in order to close resources.
97+ * </p>
98+ *
99+ * @param type A type of message.
100+ * @param reader A read context.
101+ * @param <T> Target type.
102+ * @return A body message.
103+ * @throws Exception If read operation fail.
104+ */
105+ @ Nonnull
106+ default <T > T parse (@ Nonnull final Class <T > type , @ Nonnull final Body .Reader reader )
107+ throws Exception {
108+ return parse (TypeLiteral .get (type ), reader );
109+ }
110+
76111 /**
77112 * Attempt to read a message from HTTP request body.
78113 * <p>
0 commit comments