forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageDecoder.java
More file actions
37 lines (32 loc) · 904 Bytes
/
MessageDecoder.java
File metadata and controls
37 lines (32 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* Jooby https://jooby.io
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
* Copyright 2014 Edgar Espina
*/
package io.jooby;
import io.jooby.exception.UnsupportedMediaType;
import javax.annotation.Nonnull;
import java.lang.reflect.Type;
/**
* Parse HTTP body into a target type.
*
* @since 2.0.0
* @author edgar
*/
public interface MessageDecoder {
/**
* Resolve parsing as {@link StatusCode#UNSUPPORTED_MEDIA_TYPE}.
*/
MessageDecoder UNSUPPORTED_MEDIA_TYPE = (ctx, type) -> {
throw new UnsupportedMediaType(ctx.header("Content-Type").valueOrNull());
};
/**
* Parse HTTP body into the given type.
*
* @param ctx Web context.
* @param type Target/expected type.
* @return An instance of the target type.
* @throws Exception Is something goes wrong.
*/
@Nonnull Object decode(@Nonnull Context ctx, @Nonnull Type type) throws Exception;
}