Polishing

This commit is contained in:
Juergen Hoeller
2014-01-05 00:02:54 +01:00
parent be2d915cc2
commit 72a5737ab9
3 changed files with 41 additions and 42 deletions

View File

@@ -45,7 +45,7 @@ import org.springframework.util.Assert;
* <p>Example usage with
* {@link org.springframework.http.converter.json.MappingJackson2HttpMessageConverter}:
*
* <pre>
* <pre class="code">
* &lt;bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
* &lt;property name="objectMapper">
* &lt;bean class="org.springframework.web.context.support.Jackson2ObjectMapperFactoryBean"
@@ -58,7 +58,7 @@ import org.springframework.util.Assert;
*
* <p>Example usage with MappingJackson2JsonView:
*
* <pre>
* <pre class="code">
* &lt;bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
* &lt;property name="objectMapper">
* &lt;bean class="org.springframework.web.context.support.Jackson2ObjectMapperFactoryBean"
@@ -78,7 +78,7 @@ import org.springframework.util.Assert;
* options), you can still use the more general methods
* {@link #setFeaturesToEnable(Object[])} and {@link #setFeaturesToDisable(Object[])}.
*
* <pre>
* <pre class="code">
* &lt;bean class="org.springframework.web.context.support.Jackson2ObjectMapperFactoryBean">
* &lt;property name="featuresToEnable">
* &lt;array>
@@ -102,8 +102,6 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
private ObjectMapper objectMapper;
private Map<Object, Boolean> features = new HashMap<Object, Boolean>();
private DateFormat dateFormat;
private AnnotationIntrospector annotationIntrospector;
@@ -112,6 +110,8 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
private final Map<Class<?>, JsonDeserializer<?>> deserializers = new LinkedHashMap<Class<?>, JsonDeserializer<?>>();
private final Map<Object, Boolean> features = new HashMap<Object, Boolean>();
/**
* Set the ObjectMapper instance to use. If not set, the ObjectMapper will
@@ -142,8 +142,7 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
}
/**
* Set the {@link AnnotationIntrospector} for both serialization and
* deserialization.
* Set an {@link AnnotationIntrospector} for both serialization and deserialization.
*/
public void setAnnotationIntrospector(AnnotationIntrospector annotationIntrospector) {
this.annotationIntrospector = annotationIntrospector;
@@ -257,6 +256,10 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
this.objectMapper.setDateFormat(this.dateFormat);
}
if (this.annotationIntrospector != null) {
this.objectMapper.setAnnotationIntrospector(this.annotationIntrospector);
}
if (!this.serializers.isEmpty() || !this.deserializers.isEmpty()) {
SimpleModule module = new SimpleModule();
addSerializers(module);
@@ -264,10 +267,6 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
this.objectMapper.registerModule(module);
}
if (this.annotationIntrospector != null) {
this.objectMapper.setAnnotationIntrospector(this.annotationIntrospector);
}
for (Object feature : this.features.keySet()) {
configureFeature(feature, this.features.get(feature));
}
@@ -304,7 +303,7 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
this.objectMapper.configure((MapperFeature) feature, enabled);
}
else {
throw new FatalBeanException("Unknown feature class " + feature.getClass().getName());
throw new FatalBeanException("Unknown feature class: " + feature.getClass().getName());
}
}