Jackson2ObjectMapperBuilder allows for regular constructor usage as well

Issue: SPR-12243
This commit is contained in:
Juergen Hoeller 2014-10-01 02:29:46 +02:00
parent 3a3c52dbdd
commit 20a8416c2e
2 changed files with 23 additions and 25 deletions

View File

@ -56,7 +56,7 @@ import org.springframework.util.ClassUtils;
* <p>Note that Jackson's JSR-310 and Joda-Time support modules will be registered automatically
* when available (and when Java 8 and Joda-Time themselves are available, respectively).
*
* <p>Tested against Jackson 2.2 and 2.3; compatible with Jackson 2.0 and higher.
* <p>Tested against Jackson 2.2, 2.3 and 2.4; compatible with Jackson 2.0 and higher.
*
* @author Sebastien Deleuze
* @author Juergen Hoeller
@ -92,28 +92,6 @@ public class Jackson2ObjectMapperBuilder {
private ClassLoader moduleClassLoader = getClass().getClassLoader();
private Jackson2ObjectMapperBuilder() {
}
/**
* Obtain a {@link Jackson2ObjectMapperBuilder} instance in order to
* build an {@link ObjectMapper} instance.
*/
public static Jackson2ObjectMapperBuilder json() {
return new Jackson2ObjectMapperBuilder();
}
/**
* Obtain a {@link Jackson2ObjectMapperBuilder} instance in order to
* build a {@link XmlMapper} instance.
*/
@SuppressWarnings("unchecked")
public static Jackson2ObjectMapperBuilder xml() {
return new Jackson2ObjectMapperBuilder().createXmlMapper(true);
}
/**
* If set to {@code true}, an {@link XmlMapper} will be created using its
* default constructor. This is only applicable to {@link #build()} calls,
@ -499,4 +477,24 @@ public class Jackson2ObjectMapperBuilder {
}
}
// Convenience factory methods
/**
* Obtain a {@link Jackson2ObjectMapperBuilder} instance in order to
* build a regular JSON {@link ObjectMapper} instance.
*/
public static Jackson2ObjectMapperBuilder json() {
return new Jackson2ObjectMapperBuilder();
}
/**
* Obtain a {@link Jackson2ObjectMapperBuilder} instance in order to
* build an {@link XmlMapper} instance.
*/
@SuppressWarnings("unchecked")
public static Jackson2ObjectMapperBuilder xml() {
return new Jackson2ObjectMapperBuilder().createXmlMapper(true);
}
}

View File

@ -112,7 +112,7 @@ import org.springframework.beans.factory.InitializingBean;
* Note that Jackson's JSR-310 and Joda-Time support modules will be registered automatically
* when available (and when Java 8 and Joda-Time themselves are available, respectively).
*
* <p>Tested against Jackson 2.2 and 2.3; compatible with Jackson 2.0 and higher.
* <p>Tested against Jackson 2.2, 2.3 and 2.4; compatible with Jackson 2.0 and higher.
*
* @author <a href="mailto:dmitry.katsubo@gmail.com">Dmitry Katsubo</a>
* @author Rossen Stoyanchev
@ -122,7 +122,7 @@ import org.springframework.beans.factory.InitializingBean;
*/
public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper>, BeanClassLoaderAware, InitializingBean {
private final Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.json();
private final Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
private ObjectMapper objectMapper;