Class JsonbHttpMessageConverter
java.lang.Object
org.springframework.http.converter.AbstractHttpMessageConverter<Object>
org.springframework.http.converter.AbstractGenericHttpMessageConverter<Object>
org.springframework.http.converter.json.AbstractJsonHttpMessageConverter
org.springframework.http.converter.json.JsonbHttpMessageConverter
- All Implemented Interfaces:
GenericHttpMessageConverter<Object>, HttpMessageConverter<Object>
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:
-
Field Summary
Fields inherited from class AbstractJsonHttpMessageConverter
DEFAULT_CHARSETFields inherited from class AbstractHttpMessageConverter
logger -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a newJsonbHttpMessageConverterwith default configuration.JsonbHttpMessageConverter(jakarta.json.bind.Jsonb jsonb) Construct a newJsonbHttpMessageConverterwith the given delegate.JsonbHttpMessageConverter(jakarta.json.bind.JsonbConfig config) Construct a newJsonbHttpMessageConverterwith the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionjakarta.json.bind.JsonbgetJsonb()Return the configuredJsonbinstance for this converter.protected ObjectreadInternal(Type resolvedType, Reader reader) Template method that reads the JSON-bound object from the givenReader.voidsetJsonb(jakarta.json.bind.Jsonb jsonb) Set theJsonbinstance to use.protected booleanIndicates whether this message converter can write the given object multiple times.protected voidwriteInternal(Object object, @Nullable Type type, Writer writer) Template method that writes the JSON-bound object to the givenWriter.Methods inherited from class AbstractJsonHttpMessageConverter
read, readInternal, setJsonPrefix, setPrefixJson, writeInternalMethods inherited from class AbstractGenericHttpMessageConverter
canRead, canWrite, supports, write, writeInternalMethods inherited from class AbstractHttpMessageConverter
addDefaultHeaders, canRead, canRead, canWrite, canWrite, getContentLength, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, writeMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HttpMessageConverter
canRead, canWrite, getSupportedMediaTypes, getSupportedMediaTypes, read, write
-
Constructor Details
-
JsonbHttpMessageConverter
public JsonbHttpMessageConverter()Construct a newJsonbHttpMessageConverterwith default configuration. -
JsonbHttpMessageConverter
public JsonbHttpMessageConverter(jakarta.json.bind.JsonbConfig config) Construct a newJsonbHttpMessageConverterwith the given configuration.- Parameters:
config- theJsonbConfigfor the underlying delegate
-
JsonbHttpMessageConverter
public JsonbHttpMessageConverter(jakarta.json.bind.Jsonb jsonb) Construct a newJsonbHttpMessageConverterwith the given delegate.- Parameters:
jsonb- the Jsonb instance to use
-
-
Method Details
-
setJsonb
public void setJsonb(jakarta.json.bind.Jsonb jsonb) Set theJsonbinstance to use. If not set, a defaultJsonbinstance will be created.Setting a custom-configured
Jsonbis one way to take further control of the JSON serialization process.- See Also:
-
getJsonb
public jakarta.json.bind.Jsonb getJsonb()Return the configuredJsonbinstance for this converter. -
readInternal
Description copied from class:AbstractJsonHttpMessageConverterTemplate method that reads the JSON-bound object from the givenReader.- Specified by:
readInternalin classAbstractJsonHttpMessageConverter- Parameters:
resolvedType- the resolved generic typereader- theReaderto use- Returns:
- the JSON-bound object
- Throws:
Exception- in case of read/parse failures
-
writeInternal
Description copied from class:AbstractJsonHttpMessageConverterTemplate method that writes the JSON-bound object to the givenWriter.- Specified by:
writeInternalin classAbstractJsonHttpMessageConverter- Parameters:
object- the object to write to the output messagetype- the type of object to write (may benull)writer- theWriterto use- Throws:
Exception- in case of write failures
-
supportsRepeatableWrites
Description copied from class:AbstractHttpMessageConverterIndicates whether this message converter can write the given object multiple times.The default implementation returns
false.- Overrides:
supportsRepeatableWritesin classAbstractHttpMessageConverter<Object>- Parameters:
o- the object t- Returns:
trueiftcan be written repeatedly;falseotherwise
-