Skip to content

Commit

Permalink
Add constructors to take ObjectMapper
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mdeinum authored and jhoeller committed Sep 15, 2023
1 parent f628c60 commit e42e89c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public MappingJackson2MessageConverter() {
this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}

public MappingJackson2MessageConverter(ObjectMapper objectMapper) {
Assert.notNull(objectMapper, "ObjectMapper must not be null");
this.objectMapper = objectMapper;
}

/**
* Specify the {@link ObjectMapper} to use instead of using the default.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ public MappingJackson2MessageConverter(MimeType... supportedMimeTypes) {
this.objectMapper = initObjectMapper();
}

public MappingJackson2MessageConverter(ObjectMapper objectMapper) {
super(new MimeType("application", "json"), new MimeType("application", "*+json"));
Assert.notNull(objectMapper, "ObjectMapper must not be null");
this.objectMapper = objectMapper;
}



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

0 comments on commit e42e89c

Please sign in to comment.