Make ObjectMapper configurable in spring-messaging
Issue: SPR-11279
This commit is contained in:
parent
82ea9ece5c
commit
12fe9174f0
|
@ -32,6 +32,7 @@ import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
|
|
||||||
import org.springframework.messaging.Message;
|
import org.springframework.messaging.Message;
|
||||||
import org.springframework.messaging.MessageHeaders;
|
import org.springframework.messaging.MessageHeaders;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.util.MimeType;
|
import org.springframework.util.MimeType;
|
||||||
|
|
||||||
|
@ -61,6 +62,30 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the {@code ObjectMapper} for this converter.
|
||||||
|
* If not set, a default {@link ObjectMapper#ObjectMapper() ObjectMapper} is used.
|
||||||
|
* <p>Setting a custom-configured {@code ObjectMapper} is one way to take further
|
||||||
|
* control of the JSON serialization process. For example, an extended
|
||||||
|
* {@link com.fasterxml.jackson.databind.ser.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 setObjectMapper(ObjectMapper objectMapper) {
|
||||||
|
Assert.notNull(objectMapper, "ObjectMapper must not be null");
|
||||||
|
this.objectMapper = objectMapper;
|
||||||
|
configurePrettyPrint();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the underlying {@code ObjectMapper} for this converter.
|
||||||
|
*/
|
||||||
|
public ObjectMapper getObjectMapper() {
|
||||||
|
return this.objectMapper;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to use the {@link DefaultPrettyPrinter} when writing JSON.
|
* Whether to use the {@link DefaultPrettyPrinter} when writing JSON.
|
||||||
* This is a shortcut for setting up an {@code ObjectMapper} as follows:
|
* This is a shortcut for setting up an {@code ObjectMapper} as follows:
|
||||||
|
|
|
@ -85,11 +85,13 @@ public class MappingJackson2HttpMessageConverter extends AbstractHttpMessageConv
|
||||||
/**
|
/**
|
||||||
* Set the {@code ObjectMapper} for this view.
|
* Set the {@code ObjectMapper} for this view.
|
||||||
* If not set, a default {@link ObjectMapper#ObjectMapper() ObjectMapper} is used.
|
* If not set, a default {@link ObjectMapper#ObjectMapper() ObjectMapper} is used.
|
||||||
* <p>Setting a custom-configured {@code ObjectMapper} is one way to take further control of the JSON
|
* <p>Setting a custom-configured {@code ObjectMapper} is one way to take further
|
||||||
* serialization process. For example, an extended {@link org.codehaus.jackson.map.SerializerFactory}
|
* control of the JSON serialization process. For example, an extended
|
||||||
* can be configured that provides custom serializers for specific types. The other option for refining
|
* {@link com.fasterxml.jackson.databind.ser.SerializerFactory}
|
||||||
* the serialization process is to use Jackson's provided annotations on the types to be serialized,
|
* can be configured that provides custom serializers for specific types.
|
||||||
* in which case a custom-configured ObjectMapper is unnecessary.
|
* 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 setObjectMapper(ObjectMapper objectMapper) {
|
public void setObjectMapper(ObjectMapper objectMapper) {
|
||||||
Assert.notNull(objectMapper, "ObjectMapper must not be null");
|
Assert.notNull(objectMapper, "ObjectMapper must not be null");
|
||||||
|
|
Loading…
Reference in New Issue