Class GsonMessageConverter
java.lang.Object
org.springframework.messaging.converter.AbstractMessageConverter
org.springframework.messaging.converter.AbstractJsonMessageConverter
org.springframework.messaging.converter.GsonMessageConverter
- All Implemented Interfaces:
MessageConverter
,SmartMessageConverter
Implementation of
MessageConverter
that can read and write JSON
using Google Gson.- Since:
- 5.3
- Author:
- Juergen Hoeller
- See Also:
-
Gson
GsonBuilder
setGson(com.google.gson.Gson)
-
Field Summary
Fields inherited from class org.springframework.messaging.converter.AbstractMessageConverter
logger
-
Constructor Summary
ConstructorDescriptionConstruct a newGsonMessageConverter
with default configuration.GsonMessageConverter
(com.google.gson.Gson gson) Construct a newGsonMessageConverter
with the given delegate. -
Method Summary
Methods inherited from class org.springframework.messaging.converter.AbstractJsonMessageConverter
convertFromInternal, convertToInternal, supports
Methods inherited from class org.springframework.messaging.converter.AbstractMessageConverter
addSupportedMimeTypes, canConvertFrom, canConvertTo, fromMessage, fromMessage, getContentTypeResolver, getDefaultContentType, getMimeType, getSerializedPayloadClass, getSupportedMimeTypes, isStrictContentTypeMatch, setContentTypeResolver, setSerializedPayloadClass, setStrictContentTypeMatch, supportsMimeType, toMessage, toMessage
-
Constructor Details
-
GsonMessageConverter
public GsonMessageConverter()Construct a newGsonMessageConverter
with default configuration. -
GsonMessageConverter
public GsonMessageConverter(com.google.gson.Gson gson) Construct a newGsonMessageConverter
with the given delegate.- Parameters:
gson
- the Gson instance to use
-
-
Method Details
-
setGson
public void setGson(com.google.gson.Gson gson) Set theGson
instance to use. If not set, a defaultGson
instance will be used.Setting a custom-configured
Gson
is one way to take further control of the JSON serialization process.- See Also:
-
getGson
public com.google.gson.Gson getGson()Return the configuredGson
instance for this converter. -
fromJson
- Specified by:
fromJson
in classAbstractJsonMessageConverter
-
fromJson
- Specified by:
fromJson
in classAbstractJsonMessageConverter
-
toJson
- Specified by:
toJson
in classAbstractJsonMessageConverter
-
toJson
- Specified by:
toJson
in classAbstractJsonMessageConverter
-