diff options
author | Tatu Saloranta <tatu.saloranta@iki.fi> | 2020-07-02 16:12:41 -0700 |
---|---|---|
committer | Tatu Saloranta <tatu.saloranta@iki.fi> | 2020-07-02 16:12:41 -0700 |
commit | 92dda04600457176b15ba5d8cf4cfc3a22bd16aa (patch) | |
tree | 4966b32676a1f8844c59a4fbb1249c839ef93e54 | |
parent | d91cc6dbe6af0547ea6eb2429be2f94b200fc3b1 (diff) | |
parent | dc989c92413b49947f043e796d22074bcd52100c (diff) | |
download | jackson-databind-92dda04600457176b15ba5d8cf4cfc3a22bd16aa.tar.gz |
Merge branch '2.11' into 2.12
-rw-r--r-- | src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java | 25 | ||||
-rw-r--r-- | src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java | 19 |
2 files changed, 30 insertions, 14 deletions
diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java index da25f7666..2e1b1909d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java @@ -3630,7 +3630,7 @@ public class ObjectMapper public void writeValue(File resultFile, Object value) throws IOException, JsonGenerationException, JsonMappingException { - _writeValue(createGenerator(resultFile, JsonEncoding.UTF8), value); + _writeValueAndClose(createGenerator(resultFile, JsonEncoding.UTF8), value); } /** @@ -3647,7 +3647,7 @@ public class ObjectMapper public void writeValue(OutputStream out, Object value) throws IOException, JsonGenerationException, JsonMappingException { - _writeValue(createGenerator(out, JsonEncoding.UTF8), value); + _writeValueAndClose(createGenerator(out, JsonEncoding.UTF8), value); } /** @@ -3655,7 +3655,7 @@ public class ObjectMapper */ public void writeValue(DataOutput out, Object value) throws IOException { - _writeValue(createGenerator(out), value); + _writeValueAndClose(createGenerator(out), value); } /** @@ -3671,7 +3671,7 @@ public class ObjectMapper public void writeValue(Writer w, Object value) throws IOException, JsonGenerationException, JsonMappingException { - _writeValue(createGenerator(w), value); + _writeValueAndClose(createGenerator(w), value); } /** @@ -3689,7 +3689,7 @@ public class ObjectMapper // alas, we have to pull the recycler directly here... SegmentedStringWriter sw = new SegmentedStringWriter(_jsonFactory._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: @@ -3713,7 +3713,7 @@ public class ObjectMapper { ByteArrayBuilder bb = new ByteArrayBuilder(_jsonFactory._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: @@ -4423,8 +4423,10 @@ public class ObjectMapper /** * Method called to configure the generator as necessary and then * call write functionality + * + * @since 2.11.2 */ - protected final void _writeValue(JsonGenerator g, Object value) + protected final void _writeValueAndClose(JsonGenerator g, Object value) throws IOException { SerializationConfig cfg = getSerializationConfig(); @@ -4481,6 +4483,15 @@ public class ObjectMapper toClose.close(); } + /** + * @deprecated Since 2.11.2 Use {@link #_writeValueAndClose} instead + */ + @Deprecated // since 2.11.2 (to remove earliest from 2.13) + protected final void _configAndWriteValue(JsonGenerator g, Object value) throws IOException { + getSerializationConfig().initialize(g); + _writeValueAndClose(g, value); + } + /* /********************************************************** /* Internal methods for deserialization, overridable 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); |