Package io.helidon.media.jsonp.server
Class JsonSupport
- java.lang.Object
-
- io.helidon.webserver.JsonService
-
- io.helidon.media.jsonp.server.JsonSupport
-
- All Implemented Interfaces:
Handler,Service,BiConsumer<ServerRequest,ServerResponse>
public final class JsonSupport extends JsonService
It provides contains JSON-P (javax.json) support forWebServer'sRouting. It is intended to provide readers and writers forjavax.jsonobjects such asJsonObjectorJsonArray. If registered on theWeb ServerRouting, then allHandlerscan useServerRequest.content().as(...)andServerResponse.send()withJSONobjects.Get Instance
Use factory methodscreate()orcreate(io.helidon.media.jsonp.common.JsonProcessing)to acquire an instance.Usage with Routing
JsonSupportshould be registered on the routing before any business logic 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.Routing.builder() .register(JsonSupport.create()) .etc.... // Business logic related handlers// 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- See Also:
Routing,JsonStructure,JsonReader,JsonWriter
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.helidon.webserver.Handler
Handler.EntityHandler<T>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(ServerRequest request, ServerResponse response)It registers reader and writer forJsonSupportonServerRequest/ServerResponseon provided routing criteria.static JsonSupportcreate()Returns a singleton instance of JsonSupport with default configuration.static JsonSupportcreate(JsonProcessing processing)Create a JsonSupport with customized processing configuration.Reader<JsonStructure>reader()Returns a function (reader) convertingPublisherofByteBuffers to a JSON-P object.Reader<JsonStructure>reader(Charset charset)Returns a function (reader) convertingPublisherofByteBuffers to a JSON-P object.Function<JsonStructure,Flow.Publisher<DataChunk>>writer()Function<JsonStructure,Flow.Publisher<DataChunk>>writer(Charset charset)-
Methods inherited from class io.helidon.webserver.JsonService
acceptsJson, toJsonResponseType, update
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.function.BiConsumer
andThen
-
-
-
-
Method Detail
-
accept
public void accept(ServerRequest request, ServerResponse response)
It registers reader and writer forJsonSupportonServerRequest/ServerResponseon provided routing criteria.This method is called from
Routingduring 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.- Parameters:
request- a server requestresponse- a server response- See Also:
Routing
-
reader
public Reader<JsonStructure> reader(Charset charset)
Returns a function (reader) convertingPublisherofByteBuffers to a JSON-P object.It is intended for derivation of others, more specific readers.
- Parameters:
charset- a charset to use ornullfor default charset- Returns:
- the byte array content reader that transforms a publisher of byte buffers to a completion stage that
might end exceptionally with a
IllegalArgumentExceptionin case of I/O error or aJsonException
-
reader
public Reader<JsonStructure> reader()
Returns a function (reader) convertingPublisherofByteBuffers to a JSON-P object.It is intended for derivation of others, more specific readers.
- Returns:
- the byte array content reader that transforms a publisher of byte buffers to a completion stage that
might end exceptionally with a
IllegalArgumentExceptionin case of I/O error or aJsonException
-
writer
public Function<JsonStructure,Flow.Publisher<DataChunk>> writer(Charset charset)
- Parameters:
charset- a charset to use ornullfor default charset- Returns:
- created function
-
writer
public Function<JsonStructure,Flow.Publisher<DataChunk>> writer()
- Returns:
- created function
-
create
public static JsonSupport create()
Returns a singleton instance of JsonSupport with default configuration.Use
create(io.helidon.media.jsonp.common.JsonProcessing)method to create a new instance with specific configuration.- Returns:
- a singleton instance with default configuration
-
create
public static JsonSupport create(JsonProcessing processing)
Create a JsonSupport with customized processing configuration.- Parameters:
processing- processing to get JSON-P readers and writers- Returns:
- json support to register with web server
- See Also:
JsonProcessing.builder()
-
-