Я пытаюсь отправить объект JSON через websockets в SpringBoot, однако на моем контроллере я получаю следующую ошибку:
org.springframework.messaging.converter.MessageConversionException: Could not read JSON: Cannot deserialize instance of `com.websocket.demo.bean.MessageBean` out of START_ARRAY token
at [Source: (byte[])"[object Object]"; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `com.websocket.demo.bean.MessageBean` out of START_ARRAY token
at [Source: (byte[])"[object Object]"; line: 1, column: 1]
at org.springframework.messaging.converter.MappingJackson2MessageConverter.convertFromInternal(MappingJackson2MessageConverter.java:235) ~[spring-messaging-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.messaging.converter.AbstractMessageConverter.fromMessage(AbstractMessageConverter.java:181) ~[spring-messaging-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.messaging.converter.CompositeMessageConverter.fromMessage(CompositeMessageConverter.java:70) ~[spring-messaging-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver.resolveArgument(PayloadArgumentResolver.java:137) ~[spring-messaging-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:116) ~[spring-messaging-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:137) ~[spring-messaging-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:109) ~[spring-messaging-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMatch(AbstractMethodMessageHandler.java:517) [spring-messaging-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler.handleMatch(SimpAnnotationMethodMessageHandler.java:495) [spring-messaging-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler.handleMatch(SimpAnnotationMethodMessageHandler.java:88) [spring-messaging-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessageInternal(AbstractMethodMessageHandler.java:475) [spring-messaging-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessage(AbstractMethodMessageHandler.java:411) [spring-messaging-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.messaging.support.ExecutorSubscribableChannel$SendTask.run(ExecutorSubscribableChannel.java:138) [spring-messaging-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_181]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_181]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]
Вот так выглядит мой контроллер:
//This is intended to particular user;
@MessageMapping("/message")
public void processMessage( MessageBean message/* @DestinationVariable int id, @DestinationVariable int targetUserId*/ )
{
String channel = userService.generateConnectionString( message.getRecieverId() );
boolean isError = false;
if ( channel == null )
{
isError = true;
}
Map< String, Object > response = generateResponse( isError, channel, "Connection Request Sent Successfuly" );
messagingTemplate.convertAndSend( "/queue/greeting/" + message.getRecieverId(), response);
}
Объект запроса, который я пытаюсь отправить:
$scope.sendMessage1 = function()
{
$scope.subscribe(1);
$scope.message = {};
$scope.message.senderId = 2;
$scope.message.recieverId = 1;
$scope.message.text = "Hello from user 2";
var sendObject = JSON.stringify($scope.message);
//sendObject = "{"senderId":1,"recieverId":2,"text":"Hello from user 1"}"
console.log(sendObject);
client.send("/app/message",{},sendObject);
};
Может кто-нибудь сказать мне, как разрешить это исключение?