public final class JsonSupport extends 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.
create() or create(io.helidon.media.jsonp.common.JsonProcessing) to acquire an instance.
JsonSupport should be registered on the routing before any business logic handlers.
Routing.builder()
.register(JsonSupport.create())
.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.create())
.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 and Description |
|---|---|
void |
accept(ServerRequest request,
ServerResponse response)
It registers reader and writer for
JsonSupport on ServerRequest/ServerResponse on provided
routing criteria. |
static JsonSupport |
create()
Returns a singleton instance of JsonSupport with default configuration.
|
static JsonSupport |
create(JsonProcessing processing)
Create a JsonSupport with customized processing configuration.
|
Reader<JsonStructure> |
reader()
Returns a function (reader) converting
Publisher of ByteBuffers to
a JSON-P object. |
Reader<JsonStructure> |
reader(Charset charset)
Returns a function (reader) converting
Publisher of ByteBuffers to
a JSON-P object. |
void |
update(Routing.Rules routingRules)
|
Function<JsonStructure,Flow.Publisher<DataChunk>> |
writer()
|
Function<JsonStructure,Flow.Publisher<DataChunk>> |
writer(Charset charset)
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitandThenpublic 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
.create()).
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.create()).
It calls ServerRequest.next() method to invoke following handlers with
particular business logic.
accept in interface Handleraccept in interface BiConsumer<ServerRequest,ServerResponse>request - a server requestresponse - a server responseRoutingpublic Reader<JsonStructure> reader(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<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 Function<JsonStructure,Flow.Publisher<DataChunk>> writer(Charset charset)
charset - a charset to use or null for default charsetpublic Function<JsonStructure,Flow.Publisher<DataChunk>> writer()
public static JsonSupport create()
Use create(io.helidon.media.jsonp.common.JsonProcessing) method to create a new instance with specific
configuration.
public static JsonSupport create(JsonProcessing processing)
processing - processing to get JSON-P readers and writersJsonProcessing.builder()Copyright © 2018, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.