Handler, Service, java.util.function.BiConsumer<ServerRequest,ServerResponse>public final class JsonSupport extends java.lang.Object implements Service, Handler
javax.json) support for WebServer's
Routing. It is intended to provide readers and writers for javax.json objects such
as JsonObject or JsonArray. If registered on the
Web Server Routing, then all Handlers can use
ServerRequest.content().
as(...) and
ServerResponse.send()
with JSON objects.
get() or create(Map) to acquire an instance.
JsonSupport should be registered on the routing before any business logic handlers.
Routing.builder()
.register(JsonSupport.get())
.etc.... // Business logic related handlers
Instance behaves also as a routing filter. It means that it can be registered on any routing rule (for example HTTP method)
and then it can be used in following handlers with compatible rules.
// Register JsonSupport only for POST of 'foo'
Routing.builder()
.post("/foo/{}", JsonSupport.get())
.post("/foo/bar", ...) // It can use JSON structures
.get("/foo/bar", ...); // It can NOT use JSON structures
Routing,
JsonStructure,
JsonReader,
JsonWriterHandler.EntityHandler<T>| Modifier and Type | Method | Description |
|---|---|---|
void |
accept(ServerRequest request,
ServerResponse response) |
It registers reader and writer for
JsonSupport on ServerRequest/ServerResponse on provided
routing criteria. |
static JsonSupport |
create(java.util.Map<java.lang.String,?> config) |
Returns an instance of JsonSupport with provided configuration.
|
static JsonSupport |
get() |
Returns a singleton instance of JsonSupport with default configuration.
|
Reader<javax.json.JsonStructure> |
reader() |
Returns a function (reader) converting
Publisher of ByteBuffers to
a JSON-P object. |
Reader<javax.json.JsonStructure> |
reader(java.nio.charset.Charset charset) |
Returns a function (reader) converting
Publisher of ByteBuffers to
a JSON-P object. |
void |
update(Routing.Rules routingRules) |
|
java.util.function.Function<javax.json.JsonStructure,Flow.Publisher<DataChunk>> |
writer() |
|
java.util.function.Function<javax.json.JsonStructure,Flow.Publisher<DataChunk>> |
writer(java.nio.charset.Charset charset) |
public void update(Routing.Rules routingRules)
JsonSupport on ServerRequest/ServerResponse for any
HTTP method.
This method is called from Routing during build process. The user should register whole class
ot the routing: Routing.builder().register(JsonSupport.get()).
public void accept(ServerRequest request, ServerResponse response)
JsonSupport on ServerRequest/ServerResponse on provided
routing criteria.
This method is called from Routing during build process. The user should register whole class
ot the routing criteria. For example: Routing.builder().
post("/foo", JsonSupport.get()).
It calls ServerRequest.next() method to invoke following handlers with
particular business logic.
accept in interface java.util.function.BiConsumer<ServerRequest,ServerResponse>accept in interface Handlerrequest - a server requestresponse - a server responseRoutingpublic Reader<javax.json.JsonStructure> reader(java.nio.charset.Charset charset)
Publisher of ByteBuffers to
a JSON-P object.
It is intended for derivation of others, more specific readers.
charset - a charset to use or null for default charsetIllegalArgumentException in case of I/O error or
a JsonExceptionpublic Reader<javax.json.JsonStructure> reader()
Publisher of ByteBuffers to
a JSON-P object.
It is intended for derivation of others, more specific readers.
IllegalArgumentException in case of I/O error or
a JsonExceptionpublic java.util.function.Function<javax.json.JsonStructure,Flow.Publisher<DataChunk>> writer(java.nio.charset.Charset charset)
charset - a charset to use or null for default charsetpublic java.util.function.Function<javax.json.JsonStructure,Flow.Publisher<DataChunk>> writer()
public static JsonSupport get()
Use create(Map) method to create a new instance with specific configuration.
public static JsonSupport create(java.util.Map<java.lang.String,?> config)
null or empty
then returns a singleton.config - a configuration for Json factory methodsCopyright © 2018, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.