Skip to content

Commit 0656f35

Browse files
committed
Rename Parser.parse to MessageDecoder.decode
1 parent 3c14368 commit 0656f35

File tree

7 files changed

+13
-13
lines changed

7 files changed

+13
-13
lines changed

docs/asciidoc/body.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ Request body parsing is achieved using the javadoc:MessageDecoder[] functional i
5858
----
5959
public interface MessageDecoder {
6060
61-
<T> T parse(Context ctx, Type type) throws Exception;
61+
<T> T decode(Context ctx, Type type) throws Exception;
6262
}
6363
----
6464

65-
javadoc:MessageDecoder[] has a single `parse` method that takes two input arguments: `(context, type)`
65+
javadoc:MessageDecoder[] has a single `decode` method that takes two input arguments: `(context, type)`
6666
and returns a single result of the given type.
6767

6868
.JSON example:

jooby/src/main/java/io/jooby/Context.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ default long getRequestLength() {
790790
*/
791791
default @Nonnull <T> T body(@Nonnull Reified<T> type, @Nonnull MediaType contentType) {
792792
try {
793-
return parser(contentType).parse(this, type.getType());
793+
return parser(contentType).decode(this, type.getType());
794794
} catch (Exception x) {
795795
throw SneakyThrows.propagate(x);
796796
}
@@ -817,7 +817,7 @@ default long getRequestLength() {
817817
*/
818818
default @Nonnull <T> T body(@Nonnull Class type, @Nonnull MediaType contentType) {
819819
try {
820-
return parser(contentType).parse(this, type);
820+
return parser(contentType).decode(this, type);
821821
} catch (Exception x) {
822822
throw SneakyThrows.propagate(x);
823823
}

jooby/src/main/java/io/jooby/MessageDecoder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ public interface MessageDecoder {
2020
* Resolve parsing as {@link StatusCode#UNSUPPORTED_MEDIA_TYPE}.
2121
*/
2222
MessageDecoder UNSUPPORTED_MEDIA_TYPE = new MessageDecoder() {
23-
@Override public <T> T parse(Context ctx, Type type) {
23+
@Override public <T> T decode(Context ctx, Type type) {
2424
throw new StatusCodeException(StatusCode.UNSUPPORTED_MEDIA_TYPE);
2525
}
2626
};
2727
/**
2828
* Parse body to one of the <code>raw</code> types: String, byte[], etc.
2929
*/
3030
MessageDecoder RAW = new MessageDecoder() {
31-
@Override public <T> T parse(Context ctx, Type type) {
31+
@Override public <T> T decode(Context ctx, Type type) {
3232
return ctx.body().to(type);
3333
}
3434
};
@@ -42,5 +42,5 @@ public interface MessageDecoder {
4242
* @return An instance of the target type.
4343
* @throws Exception Is something goes wrong.
4444
*/
45-
@Nonnull <T> T parse(@Nonnull Context ctx, @Nonnull Type type) throws Exception;
45+
@Nonnull <T> T decode(@Nonnull Context ctx, @Nonnull Type type) throws Exception;
4646
}

modules/jooby-jackson/src/main/java/io/jooby/json/JacksonModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public JacksonModule() {
6464
return mapper.writeValueAsBytes(value);
6565
}
6666

67-
@Override public <T> T parse(Context ctx, Type type) throws Exception {
67+
@Override public <T> T decode(Context ctx, Type type) throws Exception {
6868
JavaType javaType = mapper.getTypeFactory().constructType(type);
6969
Body body = ctx.body();
7070
if (body.isInMemory()) {

modules/jooby-jackson/src/test/java/io/jooby/json/JacksonModuleTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void parse() throws Exception {
4040

4141
JacksonModule jackson = new JacksonModule();
4242

43-
Map<String, String> result = jackson.parse(ctx, Map.class);
43+
Map<String, String> result = jackson.decode(ctx, Map.class);
4444
assertEquals(mapOf("k", "v"), result);
4545
}
4646

tests/src/test/java/io/jooby/FeaturedTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,14 +847,14 @@ class Message {
847847
public void consumes() {
848848
new JoobyRunner(app -> {
849849
app.parser(io.jooby.MediaType.json, new MessageDecoder() {
850-
@Nonnull @Override public String parse(@Nonnull Context ctx, @Nonnull Type type)
850+
@Nonnull @Override public String decode(@Nonnull Context ctx, @Nonnull Type type)
851851
throws Exception {
852852
return "{" + ctx.body().value() + "}";
853853
}
854854
});
855855

856856
app.parser(xml, new MessageDecoder() {
857-
@Nonnull @Override public String parse(@Nonnull Context ctx, @Nonnull Type type)
857+
@Nonnull @Override public String decode(@Nonnull Context ctx, @Nonnull Type type)
858858
throws Exception {
859859
return "<" + ctx.body().value() + ">";
860860
}

tests/src/test/java/io/jooby/MvcTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ public void producesAndConsumes() {
6969
);
7070

7171
app.parser(io.jooby.MediaType.json, new MessageDecoder() {
72-
@Nonnull @Override public Message parse(@Nonnull Context ctx, @Nonnull Type type)
72+
@Nonnull @Override public Message decode(@Nonnull Context ctx, @Nonnull Type type)
7373
throws Exception {
7474
return new Message("{" + ctx.body().value() + "}");
7575
}
7676
});
7777

7878
app.parser(xml, new MessageDecoder() {
79-
@Nonnull @Override public Message parse(@Nonnull Context ctx, @Nonnull Type type)
79+
@Nonnull @Override public Message decode(@Nonnull Context ctx, @Nonnull Type type)
8080
throws Exception {
8181
return new Message("<" + ctx.body().value() + ">");
8282
}

0 commit comments

Comments
 (0)