Spring 5 M2 - 反应性 - 序列化 ServerSentEvent 时出错
Spring 5 M2 - Reactive - Error while serializing ServerSentEvent
从 Spring 5.0.0 M1 升级到 M2 后,此代码已停止工作(我从 SseEvent
更改为 ServerSentEvent
class):
@RestController
public class StringsRestController {
@GetMapping("/strings/sse/event")
public Flux<ServerSentEvent<String>> sse() {
return Flux.interval(Duration.ofMillis(100)).map(l -> {
ServerSentEvent<String> event = ServerSentEvent.builder("foo").build();
return event;
}).take(2);
}
例外情况是:
Caused by: com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.springframework.http.codec.ServerSentEvent and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:275) ~[jackson-databind-2.8.3.jar:2.8.3]
at com.fasterxml.jackson.databind.SerializerProvider.mappingException(SerializerProvider.java:1110) ~[jackson-databind-2.8.3.jar:2.8.3]
地址在https://jira.spring.io/browse/SPR-14748
返回Flux<ServerSentEvent<String>>
将意味着text/event-stream
序列化。
从 Spring 5.0.0 M1 升级到 M2 后,此代码已停止工作(我从 SseEvent
更改为 ServerSentEvent
class):
@RestController
public class StringsRestController {
@GetMapping("/strings/sse/event")
public Flux<ServerSentEvent<String>> sse() {
return Flux.interval(Duration.ofMillis(100)).map(l -> {
ServerSentEvent<String> event = ServerSentEvent.builder("foo").build();
return event;
}).take(2);
}
例外情况是:
Caused by: com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.springframework.http.codec.ServerSentEvent and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:275) ~[jackson-databind-2.8.3.jar:2.8.3]
at com.fasterxml.jackson.databind.SerializerProvider.mappingException(SerializerProvider.java:1110) ~[jackson-databind-2.8.3.jar:2.8.3]
地址在https://jira.spring.io/browse/SPR-14748
返回Flux<ServerSentEvent<String>>
将意味着text/event-stream
序列化。