-
Notifications
You must be signed in to change notification settings - Fork 96
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
Regression: yasson on SpringBoot: IOException Stream Closed #604
Comments
Seems to be caused by #586, reverting this fixes it for me |
#586 is the correct fix according the
|
Discovered few days ago in our test system that REST/JSON based backend app logs are literally FULL of the very same error. The output stream being already closed by the moment Spring's JSON HTTP message converter attempts to write the response and flush it to the (http) output stream. After some code analysis, I reached the same offending change (#586 ) that someone introduced into Yasson 3.0.3 to supposedly auto-close the generators and parsers... Well, it ruins the intent of original fix (#389 ) as can be clearly evident from @Override
public String toJson(Object object, Type type) throws JsonbException {
StringWriter writer = new StringWriter();
try (JsonGenerator generator = writerGenerator(writer)) {
new SerializationContextImpl(jsonbContext, type).marshall(object, generator);
}
return writer.toString();
}
@Override
public void toJson(Object object, Writer writer) throws JsonbException {
final SerializationContextImpl marshaller = new SerializationContextImpl(jsonbContext);
try (JsonGenerator generator = writerGenerator(writer)) {
marshaller.marshallWithoutClose(object, generator);
}
} The try-with-resources obviously closes the JSON generator once the "marshall-WITHOUT-close" (emphasis mine) method completes. Why close the resource if the intent is NOT to close it?... Sorry for the rant. System information:
|
The #631 did resolve the implicitly closing the output STREAMS when generating JSON content, but my particular issue is with (output) WRITERS, not streams. They should not be closed by Yasson code either if a ready-to-use Writer has been passed in by the calling code; the calling code is supposed to take care of its resources and objects. |
Describe the bug
It seems there is a regression on the following issue #389. I originally reported the issue here spring-projects/spring-boot#35651.
To Reproduce
Expected behavior
toJson
not closing the writer.System information:
Additional context
This issue seems to be introduced with version 3.0.3. Version 3.0.2 and below work as expected.
The text was updated successfully, but these errors were encountered: