Skip to content

Commit 20a8416

Browse files
committed
Jackson2ObjectMapperBuilder allows for regular constructor usage as well
Issue: SPR-12243
1 parent 3a3c52d commit 20a8416

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
* <p>Note that Jackson's JSR-310 and Joda-Time support modules will be registered automatically
5757
* when available (and when Java 8 and Joda-Time themselves are available, respectively).
5858
*
59-
* <p>Tested against Jackson 2.2 and 2.3; compatible with Jackson 2.0 and higher.
59+
* <p>Tested against Jackson 2.2, 2.3 and 2.4; compatible with Jackson 2.0 and higher.
6060
*
6161
* @author Sebastien Deleuze
6262
* @author Juergen Hoeller
@@ -92,28 +92,6 @@ public class Jackson2ObjectMapperBuilder {
9292
private ClassLoader moduleClassLoader = getClass().getClassLoader();
9393

9494

95-
private Jackson2ObjectMapperBuilder() {
96-
}
97-
98-
99-
/**
100-
* Obtain a {@link Jackson2ObjectMapperBuilder} instance in order to
101-
* build an {@link ObjectMapper} instance.
102-
*/
103-
public static Jackson2ObjectMapperBuilder json() {
104-
return new Jackson2ObjectMapperBuilder();
105-
}
106-
107-
/**
108-
* Obtain a {@link Jackson2ObjectMapperBuilder} instance in order to
109-
* build a {@link XmlMapper} instance.
110-
*/
111-
@SuppressWarnings("unchecked")
112-
public static Jackson2ObjectMapperBuilder xml() {
113-
return new Jackson2ObjectMapperBuilder().createXmlMapper(true);
114-
}
115-
116-
11795
/**
11896
* If set to {@code true}, an {@link XmlMapper} will be created using its
11997
* default constructor. This is only applicable to {@link #build()} calls,
@@ -499,4 +477,24 @@ private void registerWellKnownModulesIfAvailable(ObjectMapper objectMapper) {
499477
}
500478
}
501479

480+
481+
// Convenience factory methods
482+
483+
/**
484+
* Obtain a {@link Jackson2ObjectMapperBuilder} instance in order to
485+
* build a regular JSON {@link ObjectMapper} instance.
486+
*/
487+
public static Jackson2ObjectMapperBuilder json() {
488+
return new Jackson2ObjectMapperBuilder();
489+
}
490+
491+
/**
492+
* Obtain a {@link Jackson2ObjectMapperBuilder} instance in order to
493+
* build an {@link XmlMapper} instance.
494+
*/
495+
@SuppressWarnings("unchecked")
496+
public static Jackson2ObjectMapperBuilder xml() {
497+
return new Jackson2ObjectMapperBuilder().createXmlMapper(true);
498+
}
499+
502500
}

spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBean.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
* Note that Jackson's JSR-310 and Joda-Time support modules will be registered automatically
113113
* when available (and when Java 8 and Joda-Time themselves are available, respectively).
114114
*
115-
* <p>Tested against Jackson 2.2 and 2.3; compatible with Jackson 2.0 and higher.
115+
* <p>Tested against Jackson 2.2, 2.3 and 2.4; compatible with Jackson 2.0 and higher.
116116
*
117117
* @author <a href="mailto:[email protected]">Dmitry Katsubo</a>
118118
* @author Rossen Stoyanchev
@@ -122,7 +122,7 @@
122122
*/
123123
public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper>, BeanClassLoaderAware, InitializingBean {
124124

125-
private final Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.json();
125+
private final Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
126126

127127
private ObjectMapper objectMapper;
128128

0 commit comments

Comments
 (0)