Modifier and Type | Field and Description |
---|---|
static Charset |
DEFAULT_CHARSET |
Constructor and Description |
---|
MappingJacksonHttpMessageConverter()
Construct a new
BindingJacksonHttpMessageConverter . |
Modifier and Type | Method and Description |
---|---|
boolean |
canRead(Class<?> clazz,
org.springframework.http.MediaType mediaType) |
boolean |
canWrite(Class<?> clazz,
org.springframework.http.MediaType mediaType) |
protected org.codehaus.jackson.type.JavaType |
getJavaType(Class<?> clazz)
Returns the Jackson
JavaType for the specific class. |
protected Object |
readInternal(Class<?> clazz,
org.springframework.http.HttpInputMessage inputMessage) |
void |
setObjectMapper(org.codehaus.jackson.map.ObjectMapper objectMapper)
Sets the
ObjectMapper for this view. |
void |
setPrefixJson(boolean prefixJson)
Indicates whether the JSON output by this view should be prefixed with "{} &&".
|
protected boolean |
supports(Class<?> clazz) |
protected void |
writeInternal(Object o,
org.springframework.http.HttpOutputMessage outputMessage) |
public static final Charset DEFAULT_CHARSET
public MappingJacksonHttpMessageConverter()
BindingJacksonHttpMessageConverter
.public void setObjectMapper(org.codehaus.jackson.map.ObjectMapper objectMapper)
ObjectMapper
for this view. If not set, a default
ObjectMapper
is used.
Setting a custom-configured ObjectMapper
is one way to take further control of the JSON serialization
process. For example, an extended SerializerFactory
can be configured that provides
custom serializers for specific types. The other option for refining the serialization process is to use Jackson's
provided annotations on the types to be serialized, in which case a custom-configured ObjectMapper is unnecessary.
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)
protected org.codehaus.jackson.type.JavaType getJavaType(Class<?> clazz)
JavaType
for the specific class.
Default implementation returns TypeFactory.type(java.lang.reflect.Type)
, but this can be overridden
in subclasses, to allow for custom generic collection handling. For instance:
protected JavaType getJavaType(Class<?> clazz) { if (List.class.isAssignableFrom(clazz)) { return TypeFactory.collectionType(ArrayList.class, MyBean.class); } else { return super.getJavaType(clazz); } }
clazz
- the class to return the java type forpublic 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>
IOException
org.springframework.http.converter.HttpMessageNotReadableException
protected 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>
IOException
org.springframework.http.converter.HttpMessageNotWritableException
Copyright © 2006–2018 TinyGroup. All rights reserved.