spring-framework / org.springframework.http.converter.json / GsonHttpMessageConverter

GsonHttpMessageConverter

open class GsonHttpMessageConverter : AbstractJsonHttpMessageConverter

Implementation of org.springframework.http.converter.HttpMessageConverter that can read and write JSON using the Google Gson library.

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.

Tested against Gson 2.6; compatible with Gson 2.0 and higher.

Author
Roy Clarkson

Author
Juergen Hoeller

Since
4.1

See Also
com.google.gson.Gsoncom.google.gson.GsonBuilder#setGson

Constructors

<init>

GsonHttpMessageConverter()

Construct a new GsonHttpMessageConverter with default configuration.

GsonHttpMessageConverter(gson: Gson)

Construct a new GsonHttpMessageConverter with the given delegate.

Functions

getGson

open fun getGson(): Gson

Return the configured Gson instance for this converter.

setGson

open fun setGson(gson: Gson): Unit

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.