public class GsonHttpMessageConverterForSpring3 extends org.springframework.http.converter.AbstractHttpMessageConverter<Object>
| Modifier and Type | Field and Description |
|---|---|
static Charset |
DEFAULT_CHARSET |
| Constructor and Description |
|---|
GsonHttpMessageConverterForSpring3()
Construct a new
GsonHttpMessageConverter with a default Gson. |
GsonHttpMessageConverterForSpring3(boolean serializeNulls)
Construct a new
GsonHttpMessageConverter. |
GsonHttpMessageConverterForSpring3(com.google.gson.Gson gson)
Construct a new
GsonHttpMessageConverter. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canRead(Class<?> clazz,
org.springframework.http.MediaType mediaType) |
boolean |
canWrite(Class<?> clazz,
org.springframework.http.MediaType mediaType) |
Type |
getType() |
protected Object |
readInternal(Class<?> clazz,
org.springframework.http.HttpInputMessage inputMessage) |
void |
setGson(com.google.gson.Gson gson)
Sets the
Gson for this view. |
void |
setPrefixJson(boolean prefixJson)
Indicates whether the JSON output by this view should be prefixed with "{} &&".
|
void |
setType(Type type) |
protected boolean |
supports(Class<?> clazz) |
protected void |
writeInternal(Object o,
org.springframework.http.HttpOutputMessage outputMessage) |
public static final Charset DEFAULT_CHARSET
public GsonHttpMessageConverterForSpring3()
GsonHttpMessageConverter with a default Gson.public GsonHttpMessageConverterForSpring3(boolean serializeNulls)
GsonHttpMessageConverter.serializeNulls - true to generate json for null valuespublic GsonHttpMessageConverterForSpring3(com.google.gson.Gson gson)
GsonHttpMessageConverter.gson - a customized Gsonpublic void setGson(com.google.gson.Gson gson)
Gson for this view. If not set, a default
Gson is used.
Setting a custom-configured Gson is one way to take further control of the JSON serialization
process.
IllegalArgumentException - if gson is nullpublic void setType(Type type)
public Type getType()
public void setPrefixJson(boolean prefixJson)
Prefixing the JSON string in this manner is used to help prevent JSON Hijacking. The prefix renders the string syntactically invalid as a script so that it cannot be hijacked. This prefix does not affect the evaluation of JSON, but if JSON validation is performed on the string, the prefix would need to be ignored.
public boolean canRead(Class<?> clazz, org.springframework.http.MediaType mediaType)
public boolean canWrite(Class<?> clazz, org.springframework.http.MediaType mediaType)
protected boolean supports(Class<?> clazz)
supports in class org.springframework.http.converter.AbstractHttpMessageConverter<Object>protected Object readInternal(Class<?> clazz, org.springframework.http.HttpInputMessage inputMessage) throws IOException, org.springframework.http.converter.HttpMessageNotReadableException
readInternal in class org.springframework.http.converter.AbstractHttpMessageConverter<Object>IOExceptionorg.springframework.http.converter.HttpMessageNotReadableExceptionprotected void writeInternal(Object o, org.springframework.http.HttpOutputMessage outputMessage) throws IOException, org.springframework.http.converter.HttpMessageNotWritableException
writeInternal in class org.springframework.http.converter.AbstractHttpMessageConverter<Object>IOExceptionorg.springframework.http.converter.HttpMessageNotWritableExceptionCopyright © 2016. All rights reserved.