Skip to content

Commit e42e89c

Browse files
mdeinumjhoeller
authored andcommitted
Add constructors to take ObjectMapper
Prior to this commit in the message converters it was possible to set a pre-configured ObjectMapper. However the constructor would still create and configure an ObjectMapper. With the added constructor it is now possible to directly construct the message converter with the proper ObjectMapper. This prevents the this additional ObjectMapper to be constructed.
1 parent f628c60 commit e42e89c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ public MappingJackson2MessageConverter() {
9696
this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
9797
}
9898

99+
public MappingJackson2MessageConverter(ObjectMapper objectMapper) {
100+
Assert.notNull(objectMapper, "ObjectMapper must not be null");
101+
this.objectMapper = objectMapper;
102+
}
103+
99104
/**
100105
* Specify the {@link ObjectMapper} to use instead of using the default.
101106
*/

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ public MappingJackson2MessageConverter(MimeType... supportedMimeTypes) {
8585
this.objectMapper = initObjectMapper();
8686
}
8787

88+
public MappingJackson2MessageConverter(ObjectMapper objectMapper) {
89+
super(new MimeType("application", "json"), new MimeType("application", "*+json"));
90+
Assert.notNull(objectMapper, "ObjectMapper must not be null");
91+
this.objectMapper = objectMapper;
92+
}
93+
94+
8895

8996
@SuppressWarnings("deprecation") // on Jackson 2.13: configure(MapperFeature, boolean)
9097
private ObjectMapper initObjectMapper() {

0 commit comments

Comments
 (0)