-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
IonObjectMapper close()s the provided IonWriter unnecessarily #189
Comments
I started writing a PR for this and realized that the fix is slightly more complex than I thought.
However, we need I've created a patch that adds a new member field to I'd like to bump the |
Maybe do separate ones, although not a big deal if they were combined. Plan itself sounds right, and the only thing I would add it that for many uses it might be better to use (or implement, if support missing) |
Ah, interesting! I wasn't aware of the I've opened PR #190 to prevent Assuming that it can be merged, how do you normally propagate this sort of change to later Jackson release branches? ( |
I will merge forward fixes; 2.11 should be easy and clean, but from there to master manual conflict resolution is often needed. So no need to file anything other than target branch. Occasionally merge-to-master, cherry-pick back is also used. But usually easier to from oldest-to-newest. Interesting point on |
Merged, thank you! I hope I did not mangle merge to |
Great, thanks!
I took a look at the merge commits and didn't notice anything amiss. Should I check out the master branch and do some testing before I close the issue out? |
@zslayton either way is fine; if it's easy to test with |
I'm going to go ahead and close this out. If we run into any issues with the merge I'll open another PR to address it. Thanks! |
Description
It is not currently possible to re-use an
IonWriter
to serialize several values across multiple calls toIonObjectMapper#writeValue(IonWriter, Object)
. I believe this is unintentional, as the documentation for that method states that the method will not close the underlying writer.Impact
The current behavior has a few downsides:
IonWriter
results in a somewhat crypticIndexOutOfBoundsException
. This occurs because the writer maintains a list of buffers that is emptied whenclose()
is called. Subsequent writes attempt to access the first buffer in the now empty list.IonWriter
must be created for each individual value, which requires several buffers/collections/objects to be allocated and initialized. This expense likely dwarfs the cost of serialization.writeValue
causes an Ion Version Marker to be emitted, resetting the symbol table and requiring a new one to be defined for each value. This eliminates a large portion of the size savings one typically gets from encoding their data in Ion.Cause
The
ObjectMapper
class's implementation of_configAndWriteValue
callsclose()
on theJsonGenerator
that's used to serialize the provided value.Ion's implementation of
JsonGenerator
isIonGenerator
, and its implementation ofclose()
attempts to flush theIonWriter
by callingclose()
on it.Suggested Fix
I believe that
IonGenerator#close
should only call_writer.close()
if_ioContext.isResourceManaged()
is true. Otherwise, the user provided a reference to theIonWriter
being used and should have the authority toflush()
/finish()
/close()
it at their own discretion.Please let me know if you agree with this assessment. I'd be happy to put together a PR with this change. Thanks!
The text was updated successfully, but these errors were encountered: