spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.58k stars 38.13k forks source link

GsonHttpMessageConverter cannot be used in an SseEmitter because it closes the response stream [SPR-16529] #21072

Closed spring-projects-issues closed 6 years ago

spring-projects-issues commented 6 years ago

Dave Syer opened SPR-16529 and commented

GsonHttpMessageConverter cannot be used in an SseEmitter (unlike MappingJackson2HttpMessageConverter) because it closes the output stream after every element, committing the HTTP response and shutting it down in the servlet container. To verify this you only need to build an app with Jackson and an SseEmitter, then switch to Gson and see it break (only the first event is emitted).


Affects: 4.3.14

Issue Links:

Backported to: 4.3.15

spring-projects-issues commented 6 years ago

Dave Syer commented

Changing writer.close() to writer.flush() in writeInternal() works for me.