【发布时间】:2023-01-25 07:11:19
【问题描述】:
我尝试创建交互式应用程序并使用套接字。 我在套接字中通过邮递员发送数据,但是SpringBoot无法反序列化它。请帮忙)
我的dto
public class Event {
@JsonProperty("eventType")
private String eventType;
public Event(String eventType) {
this.eventType = eventType;
}
public String getEventType() {
return eventType;
}
@Override
public String toString() {
return "Event{" +
"eventType='" + eventType + '\'' +
'}';
}
}
控制器
@Controller
public class GameController {
@MessageMapping("/emit")
@SendTo("/topic/events")
public Event emitEvent(Event event) {
return event;
}
}
错误
2022-02-23 16:19:41.359 ERROR 12468 --- [nio-8080-exec-6] s.w.s.s.t.s.WebSocketServerSockJsSession : Broken data received. Terminating WebSocket connection abruptly
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `[Ljava.lang.String;` from Object value (token `JsonToken.START_OBJECT`)
at [Source: (String)"{
"eventType": "TestData"
}"; line: 1, column: 1]
更新 1:
【问题讨论】:
-
另外,我注意到,
[Ljava.lang.String;- 太奇怪了,它看起来像断线(类型),但我不知道,为什么它会出现在这里......
标签: java spring-boot websocket jackson sockjs