Skip to content

Commit aa1360b

Browse files
committed
Complete set of constructors with consistent javadoc
Closes gh-31234
1 parent e42e89c commit aa1360b

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed

spring-jms/src/main/java/org/springframework/jms/support/converter/MappingJackson2MessageConverter.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,30 @@ public class MappingJackson2MessageConverter implements SmartMessageConverter, B
8989
private ClassLoader beanClassLoader;
9090

9191

92+
/**
93+
* Construct a {@code MappingJackson2MessageConverter} with a default {@link ObjectMapper}.
94+
*/
9295
@SuppressWarnings("deprecation") // on Jackson 2.13: configure(MapperFeature, boolean)
9396
public MappingJackson2MessageConverter() {
9497
this.objectMapper = new ObjectMapper();
9598
this.objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
9699
this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
97100
}
98101

102+
/**
103+
* Construct a {@code MappingJackson2MessageConverter} with a custom {@link ObjectMapper}.
104+
* @param objectMapper the ObjectMapper to use
105+
* @since 6.1
106+
*/
99107
public MappingJackson2MessageConverter(ObjectMapper objectMapper) {
100108
Assert.notNull(objectMapper, "ObjectMapper must not be null");
101109
this.objectMapper = objectMapper;
102110
}
103111

112+
104113
/**
105-
* Specify the {@link ObjectMapper} to use instead of using the default.
114+
* Set the {@code ObjectMapper} for this converter.
115+
* If not set, a default {@link ObjectMapper#ObjectMapper() ObjectMapper} is used.
106116
*/
107117
public void setObjectMapper(ObjectMapper objectMapper) {
108118
Assert.notNull(objectMapper, "ObjectMapper must not be null");

spring-messaging/src/main/java/org/springframework/messaging/converter/MappingJackson2MessageConverter.java

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,48 +59,61 @@
5959
*/
6060
public class MappingJackson2MessageConverter extends AbstractMessageConverter {
6161

62+
private static final MimeType[] DEFAULT_MIME_TYPES = new MimeType[] {
63+
new MimeType("application", "json"), new MimeType("application", "*+json")};
64+
6265
private ObjectMapper objectMapper;
6366

6467
@Nullable
6568
private Boolean prettyPrint;
6669

6770

6871
/**
69-
* Construct a {@code MappingJackson2MessageConverter} supporting
70-
* the {@code application/json} MIME type with {@code UTF-8} character set.
72+
* Construct a {@code MappingJackson2MessageConverter} with a default {@link ObjectMapper},
73+
* supporting the {@code application/json} MIME type with {@code UTF-8} character set.
7174
*/
7275
public MappingJackson2MessageConverter() {
73-
super(new MimeType("application", "json"), new MimeType("application", "*+json"));
74-
this.objectMapper = initObjectMapper();
76+
this(DEFAULT_MIME_TYPES);
7577
}
7678

7779
/**
78-
* Construct a {@code MappingJackson2MessageConverter} supporting
79-
* one or more custom MIME types.
80+
* Construct a {@code MappingJackson2MessageConverter} with a default {@link ObjectMapper},
81+
* supporting one or more custom MIME types.
8082
* @param supportedMimeTypes the supported MIME types
8183
* @since 4.1.5
8284
*/
85+
@SuppressWarnings("deprecation") // on Jackson 2.13: configure(MapperFeature, boolean)
8386
public MappingJackson2MessageConverter(MimeType... supportedMimeTypes) {
8487
super(supportedMimeTypes);
85-
this.objectMapper = initObjectMapper();
88+
this.objectMapper = new ObjectMapper();
89+
this.objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
90+
this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
8691
}
8792

93+
/**
94+
* Construct a {@code MappingJackson2MessageConverter} with a custom {@link ObjectMapper},
95+
* supporting the {@code application/json} MIME type with {@code UTF-8} character set.
96+
* @param objectMapper the ObjectMapper to use
97+
* @since 6.1
98+
*/
8899
public MappingJackson2MessageConverter(ObjectMapper objectMapper) {
89-
super(new MimeType("application", "json"), new MimeType("application", "*+json"));
100+
this(objectMapper, DEFAULT_MIME_TYPES);
101+
}
102+
103+
/**
104+
* Construct a {@code MappingJackson2MessageConverter} with a custom {@link ObjectMapper},
105+
* supporting one or more custom MIME types.
106+
* @param objectMapper the ObjectMapper to use
107+
* @param supportedMimeTypes the supported MIME types
108+
* @since 6.1
109+
*/
110+
public MappingJackson2MessageConverter(ObjectMapper objectMapper, MimeType... supportedMimeTypes) {
111+
super(supportedMimeTypes);
90112
Assert.notNull(objectMapper, "ObjectMapper must not be null");
91113
this.objectMapper = objectMapper;
92114
}
93115

94116

95-
96-
@SuppressWarnings("deprecation") // on Jackson 2.13: configure(MapperFeature, boolean)
97-
private ObjectMapper initObjectMapper() {
98-
ObjectMapper objectMapper = new ObjectMapper();
99-
objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
100-
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
101-
return objectMapper;
102-
}
103-
104117
/**
105118
* Set the {@code ObjectMapper} for this converter.
106119
* If not set, a default {@link ObjectMapper#ObjectMapper() ObjectMapper} is used.

0 commit comments

Comments
 (0)