Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE if no registered MessageConverter supporting "application/json" MIME type [SPR-11370] #15996

spring-projects-issues opened this issue Jan 29, 2014 · 2 comments


Copy link

@spring-projects-issues spring-projects-issues commented Jan 29, 2014

Anton Moiseev opened SPR-11370 and commented

If I do not register any default MessageConverter by returning false from WebSocketMessageBrokerConfigurer's configureMessageConverters() and do not provide any custom MessageConverter that supports "application/json", I get following exception:

java.lang.NullPointerException: null
	at org.springframework.messaging.core.AbstractMessageSendingTemplate.convertAndSend(
	at org.springframework.messaging.simp.SimpMessagingTemplate.convertAndSendToUser(
	at org.springframework.messaging.simp.SimpMessagingTemplate.convertAndSendToUser(
	at org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandlerComposite.handleReturnValue(
	at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMatch(
	at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessageInternal(
	at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessage(
	at java.util.concurrent.ThreadPoolExecutor.runWorker(
	at java.util.concurrent.ThreadPoolExecutor$

Please, find detailed explanation by the provided Reference URL.

Affects: 4.0.1

Reference URL:

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 29, 2014

Rossen Stoyanchev commented

The issue is twofold. One we probably shouldn't assume a default content type if you choose not to register default converters, or at least ensure there is a converter for the default. The second issue is that if there is truly no suitable converter, it should result in a message conversion exception, not NPE.

Can you confirm if not setting the default content type, or changing to something meaningful for your case, fixes the issue? To do that you'll need to switch to the more advanced mode of configuration (remove @EnableWebSocketMessageBroker and extend directly from WebSocketMessageBrokerConfigurationSupport).

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 30, 2014

Anton Moiseev commented

Confirmed. Doing the way you described and overriding getContentTypeResolver() solves the problem:

protected ContentTypeResolver getContentTypeResolver() {
    return new DefaultContentTypeResolver();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants