Polishing
This commit is contained in:
@@ -45,7 +45,7 @@ import org.springframework.util.Assert;
|
||||
* <p>Example usage with
|
||||
* {@link org.springframework.http.converter.json.MappingJackson2HttpMessageConverter}:
|
||||
*
|
||||
* <pre>
|
||||
* <pre class="code">
|
||||
* <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
|
||||
* <property name="objectMapper">
|
||||
* <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">
|
||||
* <bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
|
||||
* <property name="objectMapper">
|
||||
* <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">
|
||||
* <bean class="org.springframework.web.context.support.Jackson2ObjectMapperFactoryBean">
|
||||
* <property name="featuresToEnable">
|
||||
* <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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user