-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Add "data:" prefix for multi-line SSE data field with Jackson #1251
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
Conversation
317b38b
to
3ba6cac
Compare
@sdeleuze I'm wondering why the Jackson2JsonEncoder has to check a hint from ServerSentEventHttpMessageWriter? Couldn't it work like it's done in the AbstractJackson2HttpMessageConverter by checking the content type of the response? If that hint is removed essentially the Jackson encoder and converter have independent, built-in support to pretty print SSE data correctly which is a good place to be. |
Good point, I missed the fact that |
Yes |
Hum in fact I am afraid we need the SSE hint, because the mime type we get at the encoder level is |
It looks like ServerSentEventMessageWriter passes application/json when it delegates to the Jacson encoder. I'm not sure that should be so actually. It's probably okay for locating the encoder but the content type of the response is text/event-stream after all. Would it cause an issue to pass text/event-stream? |
In that Jackson particular case, that would work but nothing prevent an encoder implementation to re-validate the content type by calling |
One could ask then if the JacksonEncoder supports "text/event-stream" but it's more like it's the ServerSentEventMessageWriter that supports it and delegates to other encoders. So the JacksonEncoder still only knows how to render JSON but it is also aware that's happening in the context of an SSE response. Interestingly if JacksonEncoder was in spring-core where it could be shared with non-web modules, it would be harder or not possible to do this. Having a JacksonEncoder in spring-web is paying off and it's okay to make it aware of a hint from ServerSentEventMessageWriter, which is in the codec package above. In short I'm okay with this. I would only change the hint to be more broadly about indicating that encoding is happening in the context of an SSE response -- something like SSE_CONTENT_HINT and in the Javadoc the "data:" prefixing is just an example of what the hint can be used for. |
Issue: SPR-14899
@rstoyanchev Based on the Jackson
PrettyPrinter
based trick with discussed + Jackson capabilities to specify suchPrettyPrinter
atObjectWriter
level, I think I ended up with a pretty good solution in the sense it is not intrusive and it does not lead to performance penalty. Could you say me if that's fine for you?Also could you confirm that we should apply that to
4.3.x
branch as well?Issue: SPR-14899