aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java')
-rw-r--r--src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java b/src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java
index 72c899c3c..df42a8e83 100644
--- a/src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java
+++ b/src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java
@@ -980,6 +980,9 @@ public class ObjectWriter
/**
* Method that can be used to serialize any Java value as
* JSON output, using provided {@link JsonGenerator}.
+ *<p>
+ * Note that the given {@link JsonGenerator} is not closed; caller
+ * is expected to handle that as necessary.
*/
public void writeValue(JsonGenerator g, Object value) throws IOException
{
@@ -1020,7 +1023,7 @@ public class ObjectWriter
public void writeValue(File resultFile, Object value)
throws IOException, JsonGenerationException, JsonMappingException
{
- _writeValue(createGenerator(resultFile, JsonEncoding.UTF8), value);
+ _writeValueAndClose(createGenerator(resultFile, JsonEncoding.UTF8), value);
}
/**
@@ -1037,7 +1040,7 @@ public class ObjectWriter
public void writeValue(OutputStream out, Object value)
throws IOException, JsonGenerationException, JsonMappingException
{
- _writeValue(createGenerator(out, JsonEncoding.UTF8), value);
+ _writeValueAndClose(createGenerator(out, JsonEncoding.UTF8), value);
}
/**
@@ -1053,7 +1056,7 @@ public class ObjectWriter
public void writeValue(Writer w, Object value)
throws IOException, JsonGenerationException, JsonMappingException
{
- _writeValue(createGenerator(w), value);
+ _writeValueAndClose(createGenerator(w), value);
}
/**
@@ -1062,7 +1065,7 @@ public class ObjectWriter
public void writeValue(DataOutput out, Object value)
throws IOException
{
- _writeValue(createGenerator(out), value);
+ _writeValueAndClose(createGenerator(out), value);
}
/**
@@ -1080,7 +1083,7 @@ public class ObjectWriter
// alas, we have to pull the recycler directly here...
SegmentedStringWriter sw = new SegmentedStringWriter(_generatorFactory._getBufferRecycler());
try {
- _writeValue(createGenerator(sw), value);
+ _writeValueAndClose(createGenerator(sw), value);
} catch (JsonProcessingException e) {
throw e;
} catch (IOException e) { // shouldn't really happen, but is declared as possibility so:
@@ -1104,7 +1107,7 @@ public class ObjectWriter
{
ByteArrayBuilder bb = new ByteArrayBuilder(_generatorFactory._getBufferRecycler());
try {
- _writeValue(createGenerator(bb, JsonEncoding.UTF8), value);
+ _writeValueAndClose(createGenerator(bb, JsonEncoding.UTF8), value);
} catch (JsonProcessingException e) { // to support [JACKSON-758]
throw e;
} catch (IOException e) { // shouldn't really happen, but is declared as possibility so:
@@ -1201,8 +1204,10 @@ public class ObjectWriter
/**
* Method called to configure the generator as necessary and then
* call write functionality
+ *
+ * @since 2.11.2
*/
- protected final void _writeValue(JsonGenerator gen, Object value) throws IOException
+ protected final void _writeValueAndClose(JsonGenerator gen, Object value) throws IOException
{
if (_config.isEnabled(SerializationFeature.CLOSE_CLOSEABLE) && (value instanceof Closeable)) {
_writeCloseable(gen, value);