Class MediaSupportBase<T extends MediaSupportConfig>

java.lang.Object
io.helidon.http.media.MediaSupportBase<T>
Type Parameters:
T - the configuration object used by the subtype, must extend MediaSupportConfig
All Implemented Interfaces:
NamedService, NamedService, MediaSupport
Direct Known Subclasses:
GsonSupport, JacksonSupport, JsonBindingSupport, JsonbSupport, JsonpSupport, JsonSupport

public abstract class MediaSupportBase<T extends MediaSupportConfig> extends Object implements MediaSupport
A base class that can be used to implement media support that has a few common features, such as support for MediaSupportConfig.

This base class provides checks for all four methods (client request, client response, server request, server response) and makes sure that the type is supported, and that media types match.

  • Constructor Details

    • MediaSupportBase

      protected MediaSupportBase(T config, String type)
      Construct a new support base for the specified type.
      Parameters:
      config - a MediaSupportConfig subtype to configure this instance
      type - type of the media support, such as json-binding
  • Method Details

    • name

      public String name()
      Description copied from interface: NamedService
      Name of this implementation, as provided in ConfiguredProvider.create(io.helidon.common.config.Config, String).
      Specified by:
      name in interface NamedService
      Specified by:
      name in interface NamedService
      Returns:
      name of this service
    • type

      public String type()
      Description copied from interface: NamedService
      Type of this implementation, to distinguish instances of same type, with different NamedService.name(). Use for example ConfiguredProvider.configKey() to define the type.
      Specified by:
      type in interface NamedService
      Specified by:
      type in interface NamedService
      Returns:
      type of this service
    • matchesServerRequest

      protected boolean matchesServerRequest(GenericType<?> type, Headers requestHeaders)
      Server request reader check.
      Parameters:
      type - requested type
      requestHeaders - server request headers
      Returns:
      whether we support this request and can provide a reader
    • matchesServerResponse

      protected boolean matchesServerResponse(GenericType<?> type, Headers requestHeaders, Headers responseHeaders)
      Server response writer check. Checks our content type against the Accept header of the request.
      Parameters:
      type - provided type
      requestHeaders - server request headers
      responseHeaders - server response headers
      Returns:
      whether we support this response and can provide a writer
    • matchesClientRequest

      protected boolean matchesClientRequest(GenericType<?> type, Headers requestHeaders)
      Client request writer check. Checks if the content type and type is supported.
      Parameters:
      type - provided type
      requestHeaders - client request headers
      Returns:
      whether we support this request and can provide a writer
    • matchesClientResponse

      protected boolean matchesClientResponse(GenericType<?> type, Headers responseHeaders)
      Client response reader check. Checks if the content type and type is supported.
      Parameters:
      type - requested type
      responseHeaders - client response headers
      Returns:
      whether we support this response and can provide a reader
    • isMediaTypeSupported

      protected boolean isMediaTypeSupported(HttpMediaType mediaType)
      Check whether the provided media type is one of the supported media types.
      Parameters:
      mediaType - media type to check
      Returns:
      whether it is a supported media type
    • config

      protected T config()
      The configuration object used to create this instance.
      Returns:
      the config object
    • canSerialize

      protected abstract boolean canSerialize(GenericType<?> type)
      Check whether the type is supported by this media support for serialization.
      Parameters:
      type - type to check
      Returns:
      whether this media support can handle this type
    • canDeserialize

      protected abstract boolean canDeserialize(GenericType<?> type)
      Check whether the type is supported by this media support for deserialization.
      Parameters:
      type - type to check
      Returns:
      whether this media support can handle this type