Class JsonSupport

  • All Implemented Interfaces:
    Handler, Service, BiConsumer<ServerRequest,​ServerResponse>

    public final class JsonSupport
    extends JsonService
    It provides contains JSON-P (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 Instance

    Use factory methods create() or create(io.helidon.media.jsonp.common.JsonProcessing) to acquire an instance.

    Usage with Routing

    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
     
    See Also:
    Routing, JsonStructure, JsonReader, JsonWriter