Fix line endings in new JacksonObjectMapper classes

Commit aa415d7c0c introduced
JacksonObjectMapperFactoryBean and associated tests, but with Windows
(CRLF) line endings instead of the conventional Unix (LF) line endings.

This commit converts these files to LF endings using the handy
`dos2unix` utility.

Issue: SPR-9125
This commit is contained in:
Chris Beams 2012-06-19 18:01:25 +02:00
parent 64d6605974
commit 08498d57dd
2 changed files with 421 additions and 421 deletions

View File

@ -1,250 +1,250 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.context.support; package org.springframework.web.context.support;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.codehaus.jackson.JsonGenerator; import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonParser; import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.map.AnnotationIntrospector; import org.codehaus.jackson.map.AnnotationIntrospector;
import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig; import org.codehaus.jackson.map.SerializationConfig;
import org.springframework.beans.FatalBeanException; import org.springframework.beans.FatalBeanException;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
/** /**
* A FactoryBean for creating a Jackson {@link ObjectMapper} with setters to * A FactoryBean for creating a Jackson {@link ObjectMapper} with setters to
* enable or disable Jackson features from within XML configuration. * enable or disable Jackson features from within XML configuration.
* *
* <p>Example usage with MappingJacksonHttpMessageConverter:</p> * <p>Example usage with MappingJacksonHttpMessageConverter:</p>
* <pre> * <pre>
* &lt;bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> * &lt;bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
* &lt;property name="objectMapper"> * &lt;property name="objectMapper">
* &lt;bean class="org.springframework.web.context.support.JacksonObjectMapperFactoryBean" * &lt;bean class="org.springframework.web.context.support.JacksonObjectMapperFactoryBean"
* p:autoDetectFields="false" * p:autoDetectFields="false"
* p:autoDetectGettersSetters="false" * p:autoDetectGettersSetters="false"
* p:annotationIntrospector-ref="jaxbAnnotationIntrospector" /> * p:annotationIntrospector-ref="jaxbAnnotationIntrospector" />
* &lt;/property> * &lt;/property>
* &lt;/bean> * &lt;/bean>
* </pre> * </pre>
* *
* <p>Example usage with MappingJacksonJsonView:</p> * <p>Example usage with MappingJacksonJsonView:</p>
* <pre> * <pre>
* &lt;bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"> * &lt;bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
* &lt;property name="objectMapper"> * &lt;property name="objectMapper">
* &lt;bean class="org.springframework.web.context.support.JacksonObjectMapperFactoryBean" * &lt;bean class="org.springframework.web.context.support.JacksonObjectMapperFactoryBean"
* p:autoDetectFields="false" * p:autoDetectFields="false"
* p:autoDetectGettersSetters="false" * p:autoDetectGettersSetters="false"
* p:annotationIntrospector-ref="jaxbAnnotationIntrospector" /> * p:annotationIntrospector-ref="jaxbAnnotationIntrospector" />
* &lt;/property> * &lt;/property>
* &lt;/bean> * &lt;/bean>
* </pre> * </pre>
* *
* <p>In case there are no specific setters provided (for some rarely used * <p>In case there are no specific setters provided (for some rarely used
* options), you can still use the more general methods * options), you can still use the more general methods
* {@link #setFeaturesToEnable(Object[])} and {@link #setFeaturesToDisable(Object[])}. * {@link #setFeaturesToEnable(Object[])} and {@link #setFeaturesToDisable(Object[])}.
* *
* <pre> * <pre>
* &lt;bean class="org.springframework.web.context.support.JacksonObjectMapperFactoryBean"> * &lt;bean class="org.springframework.web.context.support.JacksonObjectMapperFactoryBean">
* &lt;property name="featuresToEnable"> * &lt;property name="featuresToEnable">
* &lt;array> * &lt;array>
* &lt;util:constant static-field="org.codehaus.jackson.map.SerializationConfig$Feature.WRAP_ROOT_VALUE"/> * &lt;util:constant static-field="org.codehaus.jackson.map.SerializationConfig$Feature.WRAP_ROOT_VALUE"/>
* &lt;util:constant static-field="org.codehaus.jackson.map.SerializationConfig$Feature.CLOSE_CLOSEABLE"/> * &lt;util:constant static-field="org.codehaus.jackson.map.SerializationConfig$Feature.CLOSE_CLOSEABLE"/>
* &lt;/array> * &lt;/array>
* &lt;/property> * &lt;/property>
* &lt;property name="featuresToDisable"> * &lt;property name="featuresToDisable">
* &lt;array> * &lt;array>
* &lt;util:constant static-field="org.codehaus.jackson.map.DeserializationConfig$Feature.USE_ANNOTATIONS"/> * &lt;util:constant static-field="org.codehaus.jackson.map.DeserializationConfig$Feature.USE_ANNOTATIONS"/>
* &lt;/array> * &lt;/array>
* &lt;/property> * &lt;/property>
* &lt;/bean> * &lt;/bean>
* </pre> * </pre>
* *
* <p>Note: This BeanFctory is singleton, so if you need more than one, you'll * <p>Note: This BeanFctory is singleton, so if you need more than one, you'll
* need to configure multiple instances. * need to configure multiple instances.
* *
* @author <a href="mailto:dmitry.katsubo@gmail.com">Dmitry Katsubo</a> * @author <a href="mailto:dmitry.katsubo@gmail.com">Dmitry Katsubo</a>
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* *
* @since 3.2 * @since 3.2
*/ */
public class JacksonObjectMapperFactoryBean implements FactoryBean<ObjectMapper>, InitializingBean { public class JacksonObjectMapperFactoryBean implements FactoryBean<ObjectMapper>, InitializingBean {
private ObjectMapper objectMapper; private ObjectMapper objectMapper;
private Map<Object, Boolean> features = new HashMap<Object, Boolean>(); private Map<Object, Boolean> features = new HashMap<Object, Boolean>();
private AnnotationIntrospector annotationIntrospector; private AnnotationIntrospector annotationIntrospector;
private DateFormat dateFormat; private DateFormat dateFormat;
/** /**
* Set the ObjectMapper instance to use. * Set the ObjectMapper instance to use.
* If not set an instance will be created using the default constructor. * If not set an instance will be created using the default constructor.
*/ */
public void setObjectMapper(ObjectMapper objectMapper) { public void setObjectMapper(ObjectMapper objectMapper) {
this.objectMapper = objectMapper; this.objectMapper = objectMapper;
} }
/** /**
* Define annotationIntrospector for * Define annotationIntrospector for
* {@link SerializationConfig#setAnnotationIntrospector(AnnotationIntrospector)}. * {@link SerializationConfig#setAnnotationIntrospector(AnnotationIntrospector)}.
*/ */
public void setAnnotationIntrospector(AnnotationIntrospector annotationIntrospector) { public void setAnnotationIntrospector(AnnotationIntrospector annotationIntrospector) {
this.annotationIntrospector = annotationIntrospector; this.annotationIntrospector = annotationIntrospector;
} }
/** /**
* Define the date/time format with the given string, which is in turn used * Define the date/time format with the given string, which is in turn used
* to create a {@link SimpleDateFormat}. * to create a {@link SimpleDateFormat}.
* @see #setDateFormat(DateFormat) * @see #setDateFormat(DateFormat)
*/ */
public void setSimpleDateFormat(String format) { public void setSimpleDateFormat(String format) {
this.dateFormat = new SimpleDateFormat(format); this.dateFormat = new SimpleDateFormat(format);
} }
/** /**
* Define the format for date/time with the given {@link DateFormat} instance. * Define the format for date/time with the given {@link DateFormat} instance.
* @see #setSimpleDateFormat(String) * @see #setSimpleDateFormat(String)
*/ */
public void setDateFormat(DateFormat dateFormat) { public void setDateFormat(DateFormat dateFormat) {
this.dateFormat = dateFormat; this.dateFormat = dateFormat;
} }
/** /**
* Shortcut for {@link SerializationConfig.Feature#AUTO_DETECT_FIELDS} and * Shortcut for {@link SerializationConfig.Feature#AUTO_DETECT_FIELDS} and
* {@link DeserializationConfig.Feature#AUTO_DETECT_FIELDS}. * {@link DeserializationConfig.Feature#AUTO_DETECT_FIELDS}.
*/ */
public void setAutoDetectFields(boolean autoDetectFields) { public void setAutoDetectFields(boolean autoDetectFields) {
this.features.put(DeserializationConfig.Feature.AUTO_DETECT_FIELDS, Boolean.valueOf(autoDetectFields)); this.features.put(DeserializationConfig.Feature.AUTO_DETECT_FIELDS, Boolean.valueOf(autoDetectFields));
this.features.put(SerializationConfig.Feature.AUTO_DETECT_FIELDS, Boolean.valueOf(autoDetectFields)); this.features.put(SerializationConfig.Feature.AUTO_DETECT_FIELDS, Boolean.valueOf(autoDetectFields));
} }
/** /**
* Shortcut for {@link SerializationConfig.Feature#AUTO_DETECT_GETTERS} and * Shortcut for {@link SerializationConfig.Feature#AUTO_DETECT_GETTERS} and
* {@link DeserializationConfig.Feature#AUTO_DETECT_SETTERS}. * {@link DeserializationConfig.Feature#AUTO_DETECT_SETTERS}.
*/ */
public void setAutoDetectGettersSetters(boolean autoDetectGettersSetters) { public void setAutoDetectGettersSetters(boolean autoDetectGettersSetters) {
this.features.put(SerializationConfig.Feature.AUTO_DETECT_GETTERS, Boolean.valueOf(autoDetectGettersSetters)); this.features.put(SerializationConfig.Feature.AUTO_DETECT_GETTERS, Boolean.valueOf(autoDetectGettersSetters));
this.features.put(DeserializationConfig.Feature.AUTO_DETECT_SETTERS, Boolean.valueOf(autoDetectGettersSetters)); this.features.put(DeserializationConfig.Feature.AUTO_DETECT_SETTERS, Boolean.valueOf(autoDetectGettersSetters));
} }
/** /**
* Shortcut for {@link SerializationConfig.Feature#FAIL_ON_EMPTY_BEANS}. * Shortcut for {@link SerializationConfig.Feature#FAIL_ON_EMPTY_BEANS}.
*/ */
public void setFailOnEmptyBeans(boolean failOnEmptyBeans) { public void setFailOnEmptyBeans(boolean failOnEmptyBeans) {
this.features.put(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, Boolean.valueOf(failOnEmptyBeans)); this.features.put(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, Boolean.valueOf(failOnEmptyBeans));
} }
/** /**
* Shortcut for {@link SerializationConfig.Feature#INDENT_OUTPUT}. * Shortcut for {@link SerializationConfig.Feature#INDENT_OUTPUT}.
*/ */
public void setIndentOutput(boolean indentOutput) { public void setIndentOutput(boolean indentOutput) {
this.features.put(SerializationConfig.Feature.INDENT_OUTPUT, Boolean.valueOf(indentOutput)); this.features.put(SerializationConfig.Feature.INDENT_OUTPUT, Boolean.valueOf(indentOutput));
} }
/** /**
* Specify features to enable. * Specify features to enable.
* @see SerializationConfig.Feature * @see SerializationConfig.Feature
* @see DeserializationConfig.Feature * @see DeserializationConfig.Feature
* @see JsonParser.Feature * @see JsonParser.Feature
* @see JsonGenerator.Feature * @see JsonGenerator.Feature
*/ */
public void setFeaturesToEnable(Object[] featuresToEnable) { public void setFeaturesToEnable(Object[] featuresToEnable) {
if (featuresToEnable == null) { if (featuresToEnable == null) {
throw new FatalBeanException("featuresToEnable property should not be null"); throw new FatalBeanException("featuresToEnable property should not be null");
} }
for (Object feature : featuresToEnable) { for (Object feature : featuresToEnable) {
this.features.put(feature, Boolean.TRUE); this.features.put(feature, Boolean.TRUE);
} }
} }
/** /**
* Specify features to disable. * Specify features to disable.
* @see SerializationConfig.Feature * @see SerializationConfig.Feature
* @see DeserializationConfig.Feature * @see DeserializationConfig.Feature
* @see JsonParser.Feature * @see JsonParser.Feature
* @see JsonGenerator.Feature * @see JsonGenerator.Feature
*/ */
public void setFeaturesToDisable(Object[] featuresToDisable) { public void setFeaturesToDisable(Object[] featuresToDisable) {
if (featuresToDisable == null) { if (featuresToDisable == null) {
throw new FatalBeanException("featuresToDisable property should not be null"); throw new FatalBeanException("featuresToDisable property should not be null");
} }
for (Object feature : featuresToDisable) { for (Object feature : featuresToDisable) {
this.features.put(feature, Boolean.FALSE); this.features.put(feature, Boolean.FALSE);
} }
} }
public ObjectMapper getObject() { public ObjectMapper getObject() {
return this.objectMapper; return this.objectMapper;
} }
public Class<?> getObjectType() { public Class<?> getObjectType() {
return ObjectMapper.class; return ObjectMapper.class;
} }
public boolean isSingleton() { public boolean isSingleton() {
return true; return true;
} }
/** /**
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/ */
public void afterPropertiesSet() throws FatalBeanException { public void afterPropertiesSet() throws FatalBeanException {
if (this.objectMapper == null) { if (this.objectMapper == null) {
this.objectMapper = new ObjectMapper(); this.objectMapper = new ObjectMapper();
} }
if (this.annotationIntrospector != null) { if (this.annotationIntrospector != null) {
this.objectMapper.getSerializationConfig().setAnnotationIntrospector(annotationIntrospector); this.objectMapper.getSerializationConfig().setAnnotationIntrospector(annotationIntrospector);
this.objectMapper.getDeserializationConfig().setAnnotationIntrospector(annotationIntrospector); this.objectMapper.getDeserializationConfig().setAnnotationIntrospector(annotationIntrospector);
} }
if (this.dateFormat != null) { if (this.dateFormat != null) {
// Deprecated for 1.8+, use // Deprecated for 1.8+, use
// objectMapper.setDateFormat(dateFormat); // objectMapper.setDateFormat(dateFormat);
this.objectMapper.getSerializationConfig().setDateFormat(this.dateFormat); this.objectMapper.getSerializationConfig().setDateFormat(this.dateFormat);
} }
for (Map.Entry<Object, Boolean> entry : features.entrySet()) { for (Map.Entry<Object, Boolean> entry : features.entrySet()) {
setFeatureEnabled(entry.getKey(), entry.getValue().booleanValue()); setFeatureEnabled(entry.getKey(), entry.getValue().booleanValue());
} }
} }
private void setFeatureEnabled(Object feature, boolean enabled) { private void setFeatureEnabled(Object feature, boolean enabled) {
if (feature instanceof DeserializationConfig.Feature) { if (feature instanceof DeserializationConfig.Feature) {
this.objectMapper.configure((DeserializationConfig.Feature) feature, enabled); this.objectMapper.configure((DeserializationConfig.Feature) feature, enabled);
} }
else if (feature instanceof SerializationConfig.Feature) { else if (feature instanceof SerializationConfig.Feature) {
this.objectMapper.configure((SerializationConfig.Feature) feature, enabled); this.objectMapper.configure((SerializationConfig.Feature) feature, enabled);
} }
else if (feature instanceof JsonParser.Feature) { else if (feature instanceof JsonParser.Feature) {
this.objectMapper.configure((JsonParser.Feature) feature, enabled); this.objectMapper.configure((JsonParser.Feature) feature, enabled);
} }
else if (feature instanceof JsonGenerator.Feature) { else if (feature instanceof JsonGenerator.Feature) {
this.objectMapper.configure((JsonGenerator.Feature) feature, enabled); this.objectMapper.configure((JsonGenerator.Feature) feature, enabled);
} }
else { else {
throw new FatalBeanException("Unknown feature class " + feature.getClass().getName()); throw new FatalBeanException("Unknown feature class " + feature.getClass().getName());
} }
} }
} }

View File

@ -1,171 +1,171 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.context.support; package org.springframework.web.context.support;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import org.codehaus.jackson.JsonFactory; import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonGenerator; import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonParser; import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig; import org.codehaus.jackson.map.SerializationConfig;
import org.codehaus.jackson.map.introspect.NopAnnotationIntrospector; import org.codehaus.jackson.map.introspect.NopAnnotationIntrospector;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.FatalBeanException; import org.springframework.beans.FatalBeanException;
/** /**
* Test cases for {@link JacksonObjectMapperFactoryBean} class. * Test cases for {@link JacksonObjectMapperFactoryBean} class.
* *
* @author <a href="mailto:dmitry.katsubo@gmail.com">Dmitry Katsubo</a> * @author <a href="mailto:dmitry.katsubo@gmail.com">Dmitry Katsubo</a>
*/ */
public class JacksonObjectMapperFactoryBeanTests { public class JacksonObjectMapperFactoryBeanTests {
private static final String DATE_FORMAT = "yyyy-MM-dd"; private static final String DATE_FORMAT = "yyyy-MM-dd";
private JacksonObjectMapperFactoryBean factory; private JacksonObjectMapperFactoryBean factory;
@Before @Before
public void setUp() { public void setUp() {
factory = new JacksonObjectMapperFactoryBean(); factory = new JacksonObjectMapperFactoryBean();
} }
@Test(expected=FatalBeanException.class) @Test(expected=FatalBeanException.class)
public void testSetFeaturesToEnableNull() throws Exception { public void testSetFeaturesToEnableNull() throws Exception {
factory.setFeaturesToEnable(null); factory.setFeaturesToEnable(null);
factory.setFeaturesToEnable(new Object[0]); factory.setFeaturesToEnable(new Object[0]);
} }
@Test(expected=FatalBeanException.class) @Test(expected=FatalBeanException.class)
public void testSetFeaturesToDisableNull() { public void testSetFeaturesToDisableNull() {
factory.setFeaturesToDisable(null); factory.setFeaturesToDisable(null);
} }
@Test @Test
public void testSetFeaturesToEnableEmpty() { public void testSetFeaturesToEnableEmpty() {
factory.setFeaturesToEnable(new Object[0]); factory.setFeaturesToEnable(new Object[0]);
factory.setFeaturesToDisable(new Object[0]); factory.setFeaturesToDisable(new Object[0]);
} }
@Test(expected = FatalBeanException.class) @Test(expected = FatalBeanException.class)
public void testUnknownFeature() { public void testUnknownFeature() {
factory.setFeaturesToEnable(new Object[] { Boolean.TRUE }); factory.setFeaturesToEnable(new Object[] { Boolean.TRUE });
factory.afterPropertiesSet(); factory.afterPropertiesSet();
} }
@Test @Test
public void testBooleanSetters() { public void testBooleanSetters() {
factory.setAutoDetectFields(false); factory.setAutoDetectFields(false);
factory.setAutoDetectGettersSetters(false); factory.setAutoDetectGettersSetters(false);
factory.setFailOnEmptyBeans(false); factory.setFailOnEmptyBeans(false);
factory.setIndentOutput(true); factory.setIndentOutput(true);
factory.afterPropertiesSet(); factory.afterPropertiesSet();
ObjectMapper objectMapper = factory.getObject(); ObjectMapper objectMapper = factory.getObject();
SerializationConfig serializeConfig = objectMapper.getSerializationConfig(); SerializationConfig serializeConfig = objectMapper.getSerializationConfig();
DeserializationConfig deserializeConfig = objectMapper.getDeserializationConfig(); DeserializationConfig deserializeConfig = objectMapper.getDeserializationConfig();
assertFalse(serializeConfig.isEnabled(SerializationConfig.Feature.AUTO_DETECT_FIELDS)); assertFalse(serializeConfig.isEnabled(SerializationConfig.Feature.AUTO_DETECT_FIELDS));
assertFalse(deserializeConfig.isEnabled(DeserializationConfig.Feature.AUTO_DETECT_FIELDS)); assertFalse(deserializeConfig.isEnabled(DeserializationConfig.Feature.AUTO_DETECT_FIELDS));
assertFalse(serializeConfig.isEnabled(SerializationConfig.Feature.AUTO_DETECT_GETTERS)); assertFalse(serializeConfig.isEnabled(SerializationConfig.Feature.AUTO_DETECT_GETTERS));
assertFalse(deserializeConfig.isEnabled(DeserializationConfig.Feature.AUTO_DETECT_SETTERS)); assertFalse(deserializeConfig.isEnabled(DeserializationConfig.Feature.AUTO_DETECT_SETTERS));
assertFalse(serializeConfig.isEnabled(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS)); assertFalse(serializeConfig.isEnabled(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS));
assertTrue(serializeConfig.isEnabled(SerializationConfig.Feature.INDENT_OUTPUT)); assertTrue(serializeConfig.isEnabled(SerializationConfig.Feature.INDENT_OUTPUT));
} }
@Test @Test
public void testDateTimeFormatSetter() { public void testDateTimeFormatSetter() {
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
factory.setDateFormat(dateFormat); factory.setDateFormat(dateFormat);
factory.afterPropertiesSet(); factory.afterPropertiesSet();
assertEquals(dateFormat, factory.getObject().getSerializationConfig().getDateFormat()); assertEquals(dateFormat, factory.getObject().getSerializationConfig().getDateFormat());
} }
@Test @Test
public void testSimpleDateFormatStringSetter() { public void testSimpleDateFormatStringSetter() {
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
factory.setSimpleDateFormat(DATE_FORMAT); factory.setSimpleDateFormat(DATE_FORMAT);
factory.afterPropertiesSet(); factory.afterPropertiesSet();
assertEquals(dateFormat, factory.getObject().getSerializationConfig().getDateFormat()); assertEquals(dateFormat, factory.getObject().getSerializationConfig().getDateFormat());
} }
@Test @Test
public void testSimpleSetup() { public void testSimpleSetup() {
factory.afterPropertiesSet(); factory.afterPropertiesSet();
assertNotNull(factory.getObject()); assertNotNull(factory.getObject());
assertTrue(factory.isSingleton()); assertTrue(factory.isSingleton());
assertEquals(ObjectMapper.class, factory.getObjectType()); assertEquals(ObjectMapper.class, factory.getObjectType());
} }
@Test @Test
public void testCompleteSetup() { public void testCompleteSetup() {
NopAnnotationIntrospector annotationIntrospector = new NopAnnotationIntrospector(); NopAnnotationIntrospector annotationIntrospector = new NopAnnotationIntrospector();
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
assertTrue(factory.isSingleton()); assertTrue(factory.isSingleton());
assertEquals(ObjectMapper.class, factory.getObjectType()); assertEquals(ObjectMapper.class, factory.getObjectType());
factory.setObjectMapper(objectMapper); factory.setObjectMapper(objectMapper);
factory.setAnnotationIntrospector(annotationIntrospector); factory.setAnnotationIntrospector(annotationIntrospector);
factory.setFeaturesToEnable(new Object[] { factory.setFeaturesToEnable(new Object[] {
SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS,
DeserializationConfig.Feature.USE_ANNOTATIONS, DeserializationConfig.Feature.USE_ANNOTATIONS,
JsonParser.Feature.ALLOW_SINGLE_QUOTES, JsonParser.Feature.ALLOW_SINGLE_QUOTES,
JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS
}); });
factory.setFeaturesToDisable(new Object[] { factory.setFeaturesToDisable(new Object[] {
SerializationConfig.Feature.AUTO_DETECT_GETTERS, SerializationConfig.Feature.AUTO_DETECT_GETTERS,
DeserializationConfig.Feature.AUTO_DETECT_FIELDS, DeserializationConfig.Feature.AUTO_DETECT_FIELDS,
JsonParser.Feature.AUTO_CLOSE_SOURCE, JsonParser.Feature.AUTO_CLOSE_SOURCE,
JsonGenerator.Feature.QUOTE_FIELD_NAMES JsonGenerator.Feature.QUOTE_FIELD_NAMES
}); });
factory.afterPropertiesSet(); factory.afterPropertiesSet();
assertTrue(objectMapper == factory.getObject()); assertTrue(objectMapper == factory.getObject());
SerializationConfig serializeConfig = objectMapper.getSerializationConfig(); SerializationConfig serializeConfig = objectMapper.getSerializationConfig();
DeserializationConfig deserializeConfig = objectMapper.getDeserializationConfig(); DeserializationConfig deserializeConfig = objectMapper.getDeserializationConfig();
JsonFactory jsonFactory = objectMapper.getJsonFactory(); JsonFactory jsonFactory = objectMapper.getJsonFactory();
assertTrue(annotationIntrospector == serializeConfig.getAnnotationIntrospector()); assertTrue(annotationIntrospector == serializeConfig.getAnnotationIntrospector());
assertTrue(annotationIntrospector == deserializeConfig.getAnnotationIntrospector()); assertTrue(annotationIntrospector == deserializeConfig.getAnnotationIntrospector());
assertTrue(serializeConfig.isEnabled(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS)); assertTrue(serializeConfig.isEnabled(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS));
assertTrue(deserializeConfig.isEnabled(DeserializationConfig.Feature.USE_ANNOTATIONS)); assertTrue(deserializeConfig.isEnabled(DeserializationConfig.Feature.USE_ANNOTATIONS));
assertTrue(jsonFactory.isEnabled(JsonParser.Feature.ALLOW_SINGLE_QUOTES)); assertTrue(jsonFactory.isEnabled(JsonParser.Feature.ALLOW_SINGLE_QUOTES));
assertTrue(jsonFactory.isEnabled(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS)); assertTrue(jsonFactory.isEnabled(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS));
assertFalse(serializeConfig.isEnabled(SerializationConfig.Feature.AUTO_DETECT_GETTERS)); assertFalse(serializeConfig.isEnabled(SerializationConfig.Feature.AUTO_DETECT_GETTERS));
assertFalse(deserializeConfig.isEnabled(DeserializationConfig.Feature.AUTO_DETECT_FIELDS)); assertFalse(deserializeConfig.isEnabled(DeserializationConfig.Feature.AUTO_DETECT_FIELDS));
assertFalse(jsonFactory.isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE)); assertFalse(jsonFactory.isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE));
assertFalse(jsonFactory.isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES)); assertFalse(jsonFactory.isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES));
} }
} }