io.helidon.webserver.Handler, io.helidon.webserver.Service, java.util.function.BiConsumer<io.helidon.webserver.ServerRequest,io.helidon.webserver.ServerResponse>public final class JsonSupport
extends java.lang.Object
implements io.helidon.webserver.Service, io.helidon.webserver.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,
JsonWriter| Modifier and Type | Method | Description |
|---|---|---|
void |
accept(io.helidon.webserver.ServerRequest request,
io.helidon.webserver.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.
|
io.helidon.common.http.Reader<javax.json.JsonStructure> |
reader() |
Returns a function (reader) converting
Publisher of ByteBuffers to
a JSON-P object. |
io.helidon.common.http.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(io.helidon.webserver.Routing.Rules routingRules) |
|
java.util.function.Function<javax.json.JsonStructure,io.helidon.common.reactive.Flow.Publisher<io.helidon.common.http.DataChunk>> |
writer() |
Returns a function (writer) converting
JsonStructure to the Publisher
of DataChunks. |
java.util.function.Function<javax.json.JsonStructure,io.helidon.common.reactive.Flow.Publisher<io.helidon.common.http.DataChunk>> |
writer(java.nio.charset.Charset charset) |
Returns a function (writer) converting
JsonStructure to the Publisher
of DataChunks. |
public void update(io.helidon.webserver.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()).
update in interface io.helidon.webserver.ServiceroutingRules - a routing configuration where JSON support should be registeredRoutingpublic void accept(io.helidon.webserver.ServerRequest request,
io.helidon.webserver.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<io.helidon.webserver.ServerRequest,io.helidon.webserver.ServerResponse>accept in interface io.helidon.webserver.Handlerrequest - a server requestresponse - a server responseRoutingpublic io.helidon.common.http.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 io.helidon.common.http.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,io.helidon.common.reactive.Flow.Publisher<io.helidon.common.http.DataChunk>> writer(java.nio.charset.Charset charset)
JsonStructure to the Publisher
of DataChunks.charset - a charset to use or null for default charsetpublic java.util.function.Function<javax.json.JsonStructure,io.helidon.common.reactive.Flow.Publisher<io.helidon.common.http.DataChunk>> writer()
JsonStructure to the Publisher
of DataChunks.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 Corporation. All rights reserved.