Top Description Fields Constructors Methods
org.springframework.messaging.converter

public Class GsonMessageConverter

extends AbstractJsonMessageConverter
Class Inheritance
Imports
java.io.Reader, .Writer, java.lang.reflect.ParameterizedType, .Type, com.google.gson.Gson, org.springframework.util.Assert

Implementation of MessageConverter that can read and write JSON using Google Gson.
Author
Juergen Hoeller
Since
5.3
See Also
com.google.gson.Gson, com.google.gson.GsonBuilder, setGson

Field Summary

Modifier and TypeField and Description
private Gson

Constructor Summary

AccessConstructor and Description
public
GsonMessageConverter()

Construct a new GsonMessageConverter with default configuration.

public
GsonMessageConverter(Gson
the Gson instance to use
gson
)

Construct a new GsonMessageConverter with the given delegate.

Method Summary

Modifier and TypeMethod and Description
protected Object
protected Object
public Gson
getGson()

Return the configured Gson instance for this converter.

public void
setGson(Gson gson)

Set the Gson instance to use.

protected void
protected String
Inherited from org.springframework.messaging.converter.AbstractJsonMessageConverter:
convertFromInternalconvertToInternalsupports

Field Detail

gsonback to summary
private Gson gson

Constructor Detail

GsonMessageConverterback to summary
public GsonMessageConverter()

Construct a new GsonMessageConverter with default configuration.

GsonMessageConverterback to summary
public GsonMessageConverter(Gson gson)

Construct a new GsonMessageConverter with the given delegate.

Parameters
gson:Gson

the Gson instance to use

Method Detail

fromJsonback to summary
protected Object fromJson(Reader reader, Type resolvedType)

Implements abstract org.springframework.messaging.converter.AbstractJsonMessageConverter.fromJson.

Annotations
@Override
fromJsonback to summary
protected Object fromJson(String payload, Type resolvedType)

Implements abstract org.springframework.messaging.converter.AbstractJsonMessageConverter.fromJson.

Annotations
@Override
getGsonback to summary
public Gson getGson()

Return the configured Gson instance for this converter.

setGsonback to summary
public void setGson(Gson gson)

Set the Gson instance to use. If not set, a default Gson instance will be used.

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

See Also
GsonMessageConverter(Gson)
toJsonback to summary
protected void toJson(Object payload, Type resolvedType, Writer writer)

Implements abstract org.springframework.messaging.converter.AbstractJsonMessageConverter.toJson.

Annotations
@Override
toJsonback to summary
protected String toJson(Object payload, Type resolvedType)

Implements abstract org.springframework.messaging.converter.AbstractJsonMessageConverter.toJson.

Annotations
@Override