Skip to content

Commit

Permalink
fix JsonMessageConverter mimetype NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
Nephery committed Jan 30, 2024
1 parent db464c1 commit fb0af94
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected boolean canConvertFrom(Message<?> message, @Nullable Class<?> targetCl
private boolean canDiscoverConvertToType(Message<?> message, Class<?> targetClass) {
if (targetClass == null || targetClass == Object.class) {
MimeType mimeType = getMimeType(message.getHeaders());
if (StringUtils.hasText(mimeType.getParameter("type"))) {
if (mimeType != null && StringUtils.hasText(mimeType.getParameter("type"))) {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public void testTypeInference() {

Message<String> message = MessageBuilder.withPayload("{\"name\":\"bill\"}").build();
assertThat(converter.canConvertFrom(message, Person.class)).isTrue();
assertThat(converter.canConvertFrom(message, Object.class)).isFalse();
assertThat(converter.canConvertFrom(message, null)).isFalse();

message = MessageBuilder.withPayload("{\"name\":\"bill\"}").setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON).build();
assertThat(converter.canConvertFrom(message, Person.class)).isTrue();
Expand Down

0 comments on commit fb0af94

Please sign in to comment.