Skip to content

Commit 8bc983d

Browse files
committed
Rename Parser -> MessageDecoder
1 parent 2e1f53c commit 8bc983d

File tree

12 files changed

+46
-44
lines changed

12 files changed

+46
-44
lines changed

docs/asciidoc/body.adoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ Raw `request body` is available via javadoc:Context[body] method:
5050

5151
This give us the `raw body`.
5252

53-
==== Parser
53+
==== Message Decoder
5454

55-
Request body parsing is achieved using the javadoc:Parser[] functional interface.
55+
Request body parsing is achieved using the javadoc:MessageDecoder[] functional interface.
5656

5757
[source, java]
5858
----
59-
public interface Parser {
59+
public interface MessageDecoder {
6060
6161
<T> T parse(Context ctx, Type type) throws Exception;
6262
}
6363
----
6464

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

6868
.JSON example:
@@ -71,7 +71,7 @@ and returns a single result of the given type.
7171
{
7272
FavoriteJson lib = new FavoriteJson(); // <1>
7373
74-
parser(MediaType.json, (ctx, type) -> { // <2>
74+
decoder(MediaType.json, (ctx, type) -> { // <2>
7575
7676
byte[] body = ctx.body().bytes(); // <3>
7777
@@ -90,7 +90,7 @@ and returns a single result of the given type.
9090
{
9191
val lib = FavoriteJson() // <1>
9292
93-
parser(MediaType.json, { ctx, type -> // <2>
93+
decoder(MediaType.json, { ctx, type -> // <2>
9494
9595
val body = ctx.body().bytes() // <3>
9696
@@ -107,12 +107,12 @@ and returns a single result of the given type.
107107
<2> Check if the `Content-Type` header matches `application/json`
108108
<3> Ready the body as `byte[]`
109109
<4> Parse the `body` and use the requested type
110-
<5> Route handler now call the `body(Type)` function to trigger the parser function
110+
<5> Route handler now call the `body(Type)` function to trigger the decoder function
111111

112112
[TIP]
113113
====
114114
115-
Jooby comes with a `json` parser built on top of https://github.com/FasterXML/jackson-databind[Jackson]:
115+
Jooby comes with a `json` decoder built on top of https://github.com/FasterXML/jackson-databind[Jackson]:
116116
117117
[dependency, artifactId="jooby-jackson"]
118118
.

docs/asciidoc/value-api.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ value may or may not exists.
227227

228228
===== Syntax
229229

230-
Structured data parser supports `dot` and `bracket` notation:
230+
Structured data decoder supports `dot` and `bracket` notation:
231231

232232
.Dot notation
233233
----
@@ -246,13 +246,13 @@ Structured data parser supports `dot` and `bracket` notation:
246246

247247
===== POJO
248248

249-
Structured data parser is able to reconstruct a POJO (Plain Old Java Object) from:
249+
Structured data decoder is able to reconstruct a POJO (Plain Old Java Object) from:
250250

251251
- <<query, Query>> encoded as https://tools.ietf.org/html/rfc3986#section-2[RFC 3986]
252252
- <<formdata, Formdata>> encoded as `application/x-www-form-urlencoded`
253253
- <<multipart, Multipart>> encoded as `multipart/form-data`
254254

255-
We are going to use a `Group` and `Member` objects to demonstrate how the parser works:
255+
We are going to use a `Group` and `Member` objects to demonstrate how the decoder works:
256256

257257
.Example
258258
[source, java, role="primary"]
@@ -403,7 +403,7 @@ The target `POJO` must follow one of these rules:
403403
- Has multiple constructors, but only one is annotated with
404404
https://static.javadoc.io/javax.inject/javax.inject/1/javax/inject/Inject.html[Inject]
405405

406-
The parser matches HTTP parameters in the following order:
406+
The decoder matches HTTP parameters in the following order:
407407

408408
- As constructor arguments
409409
- As setter method

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -824,17 +824,17 @@ default long getRequestLength() {
824824
}
825825

826826
/* **********************************************************************************************
827-
* Body Parser
827+
* Body MessageDecoder
828828
* **********************************************************************************************
829829
*/
830830

831831
/**
832832
* Get a parser for the given content type or get an {@link StatusCode#UNSUPPORTED_MEDIA_TYPE}.
833833
*
834834
* @param contentType Content type.
835-
* @return Parser.
835+
* @return MessageDecoder.
836836
*/
837-
default @Nonnull Parser parser(@Nonnull MediaType contentType) {
837+
default @Nonnull MessageDecoder parser(@Nonnull MediaType contentType) {
838838
return getRoute().parser(contentType);
839839
}
840840

jooby/src/main/java/io/jooby/Jooby.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,9 @@ public <T> Jooby mvc(@Nonnull Class<T> router, @Nonnull Provider<T> provider) {
293293
return this;
294294
}
295295

296-
@Nonnull @Override public Jooby parser(@Nonnull MediaType contentType, @Nonnull Parser parser) {
297-
router.parser(contentType, parser);
296+
@Nonnull @Override public Jooby parser(@Nonnull MediaType contentType, @Nonnull
297+
MessageDecoder decoder) {
298+
router.parser(contentType, decoder);
298299
return this;
299300
}
300301

jooby/src/main/java/io/jooby/Parser.java renamed to jooby/src/main/java/io/jooby/MessageDecoder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@
1414
* @since 2.0.0
1515
* @author edgar
1616
*/
17-
public interface Parser {
17+
public interface MessageDecoder {
1818

1919
/**
2020
* Resolve parsing as {@link StatusCode#UNSUPPORTED_MEDIA_TYPE}.
2121
*/
22-
Parser UNSUPPORTED_MEDIA_TYPE = new Parser() {
22+
MessageDecoder UNSUPPORTED_MEDIA_TYPE = new MessageDecoder() {
2323
@Override public <T> T parse(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
*/
30-
Parser RAW = new Parser() {
30+
MessageDecoder RAW = new MessageDecoder() {
3131
@Override public <T> T parse(Context ctx, Type type) {
3232
return ctx.body().to(type);
3333
}

jooby/src/main/java/io/jooby/Route.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public interface Handler extends Serializable {
238238

239239
private static final Map EMPTY_MAP = Collections.emptyMap();
240240

241-
private Map<String, Parser> parsers = EMPTY_MAP;
241+
private Map<String, MessageDecoder> parsers = EMPTY_MAP;
242242

243243
private final String pattern;
244244

@@ -549,21 +549,21 @@ public Route(@Nonnull String method, @Nonnull String pattern, @Nonnull Handler h
549549
}
550550

551551
/**
552-
* Parser for given media type.
552+
* MessageDecoder for given media type.
553553
*
554554
* @param contentType Media type.
555-
* @return Parser.
555+
* @return MessageDecoder.
556556
*/
557-
public @Nonnull Parser parser(@Nonnull MediaType contentType) {
558-
return parsers.getOrDefault(contentType.getValue(), Parser.UNSUPPORTED_MEDIA_TYPE);
557+
public @Nonnull MessageDecoder parser(@Nonnull MediaType contentType) {
558+
return parsers.getOrDefault(contentType.getValue(), MessageDecoder.UNSUPPORTED_MEDIA_TYPE);
559559
}
560560

561561
/**
562562
* Route message decoder.
563563
*
564564
* @return Message decoders.
565565
*/
566-
public @Nonnull Map<String, Parser> getParsers() {
566+
public @Nonnull Map<String, MessageDecoder> getParsers() {
567567
return parsers;
568568
}
569569

@@ -573,7 +573,7 @@ public Route(@Nonnull String method, @Nonnull String pattern, @Nonnull Handler h
573573
* @param decoders message decoder.
574574
* @return This route.
575575
*/
576-
public @Nonnull Route setParsers(@Nonnull Map<String, Parser> decoders) {
576+
public @Nonnull Route setParsers(@Nonnull Map<String, MessageDecoder> decoders) {
577577
this.parsers = decoders;
578578
return this;
579579
}

jooby/src/main/java/io/jooby/Router.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ interface Match {
247247
@Nonnull Path getTmpdir();
248248

249249
/**
250-
* Register a parser for the given content type.
250+
* Register a decoder for the given content type.
251251
*
252252
* @param contentType Content type to match.
253-
* @param parser Parser.
253+
* @param decoder MessageDecoder.
254254
* @return This router.
255255
*/
256-
@Nonnull Router parser(@Nonnull MediaType contentType, @Nonnull Parser parser);
256+
@Nonnull Router parser(@Nonnull MediaType contentType, @Nonnull MessageDecoder decoder);
257257

258258
/**
259259
* Returns the worker thread pool. This thread pool is used to run application blocking code.

jooby/src/main/java/io/jooby/internal/RouterImpl.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import io.jooby.ExecutionMode;
1414
import io.jooby.Jooby;
1515
import io.jooby.MediaType;
16-
import io.jooby.Parser;
16+
import io.jooby.MessageDecoder;
1717
import io.jooby.Renderer;
1818
import io.jooby.ResponseHandler;
1919
import io.jooby.Route;
@@ -130,7 +130,7 @@ public Stack executor(Executor executor) {
130130

131131
private Map<Route, Executor> routeExecutor = new HashMap<>();
132132

133-
private Map<String, Parser> parsers = new HashMap<>();
133+
private Map<String, MessageDecoder> parsers = new HashMap<>();
134134

135135
private Map<String, Object> attributes = new ConcurrentHashMap<>();
136136

@@ -155,7 +155,7 @@ public RouterImpl(ClassLoader loader) {
155155
}
156156

157157
private void defaultParser() {
158-
parsers.put(MediaType.text.getValue(), Parser.RAW);
158+
parsers.put(MediaType.text.getValue(), MessageDecoder.RAW);
159159
}
160160

161161
@Nonnull @Override public Map<String, Object> getAttributes() {
@@ -248,8 +248,9 @@ public Router renderer(@Nonnull MediaType contentType, @Nonnull Renderer rendere
248248
return renderer(renderer.accept(contentType));
249249
}
250250

251-
@Nonnull @Override public Router parser(@Nonnull MediaType contentType, @Nonnull Parser parser) {
252-
parsers.put(contentType.getValue(), parser);
251+
@Nonnull @Override public Router parser(@Nonnull MediaType contentType, @Nonnull
252+
MessageDecoder decoder) {
253+
parsers.put(contentType.getValue(), decoder);
253254
return this;
254255
}
255256

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import io.jooby.Extension;
1818
import io.jooby.Jooby;
1919
import io.jooby.MediaType;
20-
import io.jooby.Parser;
20+
import io.jooby.MessageDecoder;
2121
import io.jooby.Renderer;
2222
import io.jooby.ServiceRegistry;
2323

@@ -27,7 +27,7 @@
2727
import java.util.HashSet;
2828
import java.util.Set;
2929

30-
public class JacksonModule implements Extension, Parser, Renderer {
30+
public class JacksonModule implements Extension, MessageDecoder, Renderer {
3131
private final ObjectMapper mapper;
3232

3333
private final Set<Class<?extends Module>> modules = new HashSet<>();

modules/jooby-test/src/main/java/io/jooby/MockContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class MockContext implements Context {
5151

5252
private Body body;
5353

54-
private Map<String, Parser> parsers = new HashMap<>();
54+
private Map<String, MessageDecoder> parsers = new HashMap<>();
5555

5656
private Map<String, Object> responseHeaders = new HashMap<>();
5757

@@ -217,8 +217,8 @@ MockContext setPathString(@Nonnull String pathString) {
217217
return this;
218218
}
219219

220-
@Nonnull @Override public Parser parser(@Nonnull MediaType contentType) {
221-
return parsers.getOrDefault(contentType, Parser.UNSUPPORTED_MEDIA_TYPE);
220+
@Nonnull @Override public MessageDecoder parser(@Nonnull MediaType contentType) {
221+
return parsers.getOrDefault(contentType, MessageDecoder.UNSUPPORTED_MEDIA_TYPE);
222222
}
223223

224224
@Override public boolean isInIoThread() {

0 commit comments

Comments
 (0)