Class JsonbHttpMessageConverter

All Implemented Interfaces:
GenericHttpMessageConverter<Object>, HttpMessageConverter<Object>

public class JsonbHttpMessageConverter extends AbstractJsonHttpMessageConverter
Implementation of HttpMessageConverter that can read and write JSON using the JSON Binding API.

This converter can be used to bind to typed beans or untyped HashMaps. By default, it supports application/json and application/*+json with UTF-8 character set.

Since:
5.0
Author:
Juergen Hoeller
See Also:
  • Constructor Details

    • JsonbHttpMessageConverter

      public JsonbHttpMessageConverter()
      Construct a new JsonbHttpMessageConverter with default configuration.
    • JsonbHttpMessageConverter

      public JsonbHttpMessageConverter(jakarta.json.bind.JsonbConfig config)
      Construct a new JsonbHttpMessageConverter with the given configuration.
      Parameters:
      config - the JsonbConfig for the underlying delegate
    • JsonbHttpMessageConverter

      public JsonbHttpMessageConverter(jakarta.json.bind.Jsonb jsonb)
      Construct a new JsonbHttpMessageConverter with the given delegate.
      Parameters:
      jsonb - the Jsonb instance to use
  • Method Details

    • setJsonb

      public void setJsonb(jakarta.json.bind.Jsonb jsonb)
      Set the Jsonb instance to use. If not set, a default Jsonb instance will be created.

      Setting a custom-configured Jsonb is one way to take further control of the JSON serialization process.

      See Also:
    • getJsonb

      public jakarta.json.bind.Jsonb getJsonb()
      Return the configured Jsonb instance for this converter.
    • canWriteRepeatedly

      public boolean canWriteRepeatedly(Object o, @Nullable MediaType contentType)
      Description copied from interface: HttpMessageConverter
      Indicates whether this message converter can write the given payload multiple times.

      This can be used by HTTP client libraries to know whether a message can be sent again, for example after an HTTP redirect. The default implementation returns false. This typically returns false if the payload can be read only once.

      Parameters:
      o - the object t
      contentType - the content type to use when writing.
      Returns:
      true if t can be written repeatedly; false otherwise
    • readInternal

      protected Object readInternal(Type resolvedType, Reader reader) throws Exception
      Description copied from class: AbstractJsonHttpMessageConverter
      Template method that reads the JSON-bound object from the given Reader.
      Specified by:
      readInternal in class AbstractJsonHttpMessageConverter
      Parameters:
      resolvedType - the resolved generic type
      reader - the Reader to use
      Returns:
      the JSON-bound object
      Throws:
      Exception - in case of read/parse failures
    • writeInternal

      protected void writeInternal(Object object, @Nullable Type type, Writer writer) throws Exception
      Description copied from class: AbstractJsonHttpMessageConverter
      Template method that writes the JSON-bound object to the given Writer.
      Specified by:
      writeInternal in class AbstractJsonHttpMessageConverter
      Parameters:
      object - the object to write to the output message
      type - the type of object to write (may be null)
      writer - the Writer to use
      Throws:
      Exception - in case of write failures
    • supportsRepeatableWrites

      protected boolean supportsRepeatableWrites(Object o)
      Description copied from class: AbstractHttpMessageConverter
      Indicates whether this message converter can write the given object multiple times.

      The default implementation returns false.

      Overrides:
      supportsRepeatableWrites in class AbstractHttpMessageConverter<Object>
      Parameters:
      o - the object t
      Returns:
      true if t can be written repeatedly; false otherwise