-
Notifications
You must be signed in to change notification settings - Fork 117
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
(datatypes) Add Serialization Support for Streams #3
Comments
Unfortunately haven't had time to think about this; anyone got an opinion on this one? |
@cowtowncoder Please update @Override
protected void serializeContents(final Stream<?> value, final JsonGenerator gen,
final SerializerProvider provider) throws IOException {
// Stream needs to be closed to prevent resource leaks.
try (Stream<?> stream = value) {
provider.findValueSerializer(Iterator.class, null)
.serialize(value.iterator(), gen, provider);
}
} |
Not 100% if this was in 2.9.0.pr4 or not (due to forgetting to merge 2.8); but will be in 2.9.0 final if not. |
Is there a plan for creating a StreamDeserializer that could read JSON produced by StreamSerializer? |
@cesartl I don't think there are any active plans for future work here. |
This is a rather complicated to implement well. Ideally ObjectMapper would implement readValuesAsStream similar to how readValues methods return MappingIterator. One issue however makes this rather risky, MappingIterator implements Closeable which means one will be warned if it is not closed. Stream does not implement Closeable and terminal operations do not call the close() method meaning it is very easy to leave the underlying resource open. Barring a change to the standard library, such as the addition of a closeOnTerminalOperation() method on Stream I can't see a way forward. |
To me it seems that Still, question of closing is important one: perhaps there could be "buffered" variant (which reads, closes, all in memory), and "unbuffered" that does eventually close it, if(f) iteration reaches end. |
'Ideally' was a poor choice of words, but in my defense I wrote this on my phone while walking to work 😉. What I meant was that since we have methods on Sure It's important to remember that many operations do not iterate to the end of the source, some examples:
Also if an exception is thrown in a lambda passed to a |
Ok, and just to be sure, I wouldn't be opposed to something like, say, I mean, And since we now have Then again I have used so little Java 8 that there's plenty of learning to do. |
Not necessarily. They implement AutoClosable and are meant to be used for actual resources. |
Quick update: |
What ever happened with this feature? |
(moved from earlier issue filed by @jmax01)
Here is a first pass at serializing Streams.
It works for 2.6.x and above. A 2.8.1 version is also shown.
Tests:
The text was updated successfully, but these errors were encountered: