aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/fasterxml
diff options
context:
space:
mode:
authorTatu Saloranta <tatu.saloranta@iki.fi>2020-07-02 15:54:40 -0700
committerTatu Saloranta <tatu.saloranta@iki.fi>2020-07-02 15:54:40 -0700
commitdc135ecbb660b09cd44f430d4dd1f5dd8f70e947 (patch)
tree28ad3b83edc1738fdfa39bd25aef553cc7ba6752 /src/main/java/com/fasterxml
parentca417a16753fe626814ba1b41195ebe990e9051c (diff)
downloadjackson-databind-dc135ecbb660b09cd44f430d4dd1f5dd8f70e947.tar.gz
Fixed #2783 (last changes)
Diffstat (limited to 'src/main/java/com/fasterxml')
-rw-r--r--src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java39
-rw-r--r--src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java34
2 files changed, 40 insertions, 33 deletions
diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
index 382f33cb6..385f79ba6 100644
--- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
+++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
@@ -1112,7 +1112,9 @@ public class ObjectMapper
*/
public JsonGenerator createGenerator(OutputStream out) throws IOException {
_assertNotNull("out", out);
- return _jsonFactory.createGenerator(out, JsonEncoding.UTF8);
+ JsonGenerator g = _jsonFactory.createGenerator(out, JsonEncoding.UTF8);
+ _serializationConfig.initialize(g);
+ return g;
}
/**
@@ -1125,7 +1127,9 @@ public class ObjectMapper
*/
public JsonGenerator createGenerator(OutputStream out, JsonEncoding enc) throws IOException {
_assertNotNull("out", out);
- return _jsonFactory.createGenerator(out, enc);
+ JsonGenerator g = _jsonFactory.createGenerator(out, enc);
+ _serializationConfig.initialize(g);
+ return g;
}
/**
@@ -1138,7 +1142,9 @@ public class ObjectMapper
*/
public JsonGenerator createGenerator(Writer w) throws IOException {
_assertNotNull("w", w);
- return _jsonFactory.createGenerator(w);
+ JsonGenerator g = _jsonFactory.createGenerator(w);
+ _serializationConfig.initialize(g);
+ return g;
}
/**
@@ -1151,7 +1157,9 @@ public class ObjectMapper
*/
public JsonGenerator createGenerator(File outputFile, JsonEncoding enc) throws IOException {
_assertNotNull("outputFile", outputFile);
- return _jsonFactory.createGenerator(outputFile, enc);
+ JsonGenerator g = _jsonFactory.createGenerator(outputFile, enc);
+ _serializationConfig.initialize(g);
+ return g;
}
/**
@@ -1164,7 +1172,9 @@ public class ObjectMapper
*/
public JsonGenerator createGenerator(DataOutput out) throws IOException {
_assertNotNull("out", out);
- return _jsonFactory.createGenerator(out);
+ JsonGenerator g = _jsonFactory.createGenerator(out);
+ _serializationConfig.initialize(g);
+ return g;
}
/*
@@ -3589,7 +3599,7 @@ public class ObjectMapper
public void writeValue(File resultFile, Object value)
throws IOException, JsonGenerationException, JsonMappingException
{
- _configAndWriteValue(createGenerator(resultFile, JsonEncoding.UTF8), value);
+ _writeValue(createGenerator(resultFile, JsonEncoding.UTF8), value);
}
/**
@@ -3606,7 +3616,7 @@ public class ObjectMapper
public void writeValue(OutputStream out, Object value)
throws IOException, JsonGenerationException, JsonMappingException
{
- _configAndWriteValue(createGenerator(out, JsonEncoding.UTF8), value);
+ _writeValue(createGenerator(out, JsonEncoding.UTF8), value);
}
/**
@@ -3614,7 +3624,7 @@ public class ObjectMapper
*/
public void writeValue(DataOutput out, Object value) throws IOException
{
- _configAndWriteValue(createGenerator(out), value);
+ _writeValue(createGenerator(out), value);
}
/**
@@ -3630,7 +3640,7 @@ public class ObjectMapper
public void writeValue(Writer w, Object value)
throws IOException, JsonGenerationException, JsonMappingException
{
- _configAndWriteValue(createGenerator(w), value);
+ _writeValue(createGenerator(w), value);
}
/**
@@ -3648,7 +3658,7 @@ public class ObjectMapper
// alas, we have to pull the recycler directly here...
SegmentedStringWriter sw = new SegmentedStringWriter(_jsonFactory._getBufferRecycler());
try {
- _configAndWriteValue(createGenerator(sw), value);
+ _writeValue(createGenerator(sw), value);
} catch (JsonProcessingException e) {
throw e;
} catch (IOException e) { // shouldn't really happen, but is declared as possibility so:
@@ -3672,7 +3682,7 @@ public class ObjectMapper
{
ByteArrayBuilder bb = new ByteArrayBuilder(_jsonFactory._getBufferRecycler());
try {
- _configAndWriteValue(createGenerator(bb, JsonEncoding.UTF8), value);
+ _writeValue(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:
@@ -4383,13 +4393,12 @@ public class ObjectMapper
* Method called to configure the generator as necessary and then
* call write functionality
*/
- protected final void _configAndWriteValue(JsonGenerator g, Object value)
+ protected final void _writeValue(JsonGenerator g, Object value)
throws IOException
{
SerializationConfig cfg = getSerializationConfig();
- cfg.initialize(g); // since 2.5
if (cfg.isEnabled(SerializationFeature.CLOSE_CLOSEABLE) && (value instanceof Closeable)) {
- _configAndWriteCloseable(g, value, cfg);
+ _writeCloseable(g, value, cfg);
return;
}
try {
@@ -4405,7 +4414,7 @@ public class ObjectMapper
* Helper method used when value to serialize is {@link Closeable} and its <code>close()</code>
* method is to be called right after serialization has been called
*/
- private final void _configAndWriteCloseable(JsonGenerator g, Object value, SerializationConfig cfg)
+ private final void _writeCloseable(JsonGenerator g, Object value, SerializationConfig cfg)
throws IOException
{
Closeable toClose = (Closeable) value;
diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java b/src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java
index d21250ec7..72c899c3c 100644
--- a/src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java
+++ b/src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java
@@ -255,9 +255,8 @@ public class ObjectWriter
JsonGenerator gen, boolean managedInput)
throws IOException
{
- _configureGenerator(gen);
return new SequenceWriter(_serializerProvider(),
- gen, managedInput, _prefetch)
+ _configureGenerator(gen), managedInput, _prefetch)
.init(wrapInArray);
}
@@ -675,7 +674,7 @@ public class ObjectWriter
*/
public JsonGenerator createGenerator(OutputStream out) throws IOException {
_assertNotNull("out", out);
- return _generatorFactory.createGenerator(out, JsonEncoding.UTF8);
+ return _configureGenerator(_generatorFactory.createGenerator(out, JsonEncoding.UTF8));
}
/**
@@ -688,7 +687,7 @@ public class ObjectWriter
*/
public JsonGenerator createGenerator(OutputStream out, JsonEncoding enc) throws IOException {
_assertNotNull("out", out);
- return _generatorFactory.createGenerator(out, enc);
+ return _configureGenerator(_generatorFactory.createGenerator(out, enc));
}
/**
@@ -701,7 +700,7 @@ public class ObjectWriter
*/
public JsonGenerator createGenerator(Writer w) throws IOException {
_assertNotNull("w", w);
- return _generatorFactory.createGenerator(w);
+ return _configureGenerator(_generatorFactory.createGenerator(w));
}
/**
@@ -714,7 +713,7 @@ public class ObjectWriter
*/
public JsonGenerator createGenerator(File outputFile, JsonEncoding enc) throws IOException {
_assertNotNull("outputFile", outputFile);
- return _generatorFactory.createGenerator(outputFile, enc);
+ return _configureGenerator(_generatorFactory.createGenerator(outputFile, enc));
}
/**
@@ -727,7 +726,7 @@ public class ObjectWriter
*/
public JsonGenerator createGenerator(DataOutput out) throws IOException {
_assertNotNull("out", out);
- return _generatorFactory.createGenerator(out);
+ return _configureGenerator(_generatorFactory.createGenerator(out));
}
/*
@@ -770,8 +769,7 @@ public class ObjectWriter
*/
public SequenceWriter writeValues(JsonGenerator g) throws IOException {
_assertNotNull("g", g);
- _configureGenerator(g);
- return _newSequenceWriter(false, g, false);
+ return _newSequenceWriter(false, _configureGenerator(g), false);
}
/**
@@ -1022,7 +1020,7 @@ public class ObjectWriter
public void writeValue(File resultFile, Object value)
throws IOException, JsonGenerationException, JsonMappingException
{
- _configAndWriteValue(createGenerator(resultFile, JsonEncoding.UTF8), value);
+ _writeValue(createGenerator(resultFile, JsonEncoding.UTF8), value);
}
/**
@@ -1039,7 +1037,7 @@ public class ObjectWriter
public void writeValue(OutputStream out, Object value)
throws IOException, JsonGenerationException, JsonMappingException
{
- _configAndWriteValue(createGenerator(out, JsonEncoding.UTF8), value);
+ _writeValue(createGenerator(out, JsonEncoding.UTF8), value);
}
/**
@@ -1055,7 +1053,7 @@ public class ObjectWriter
public void writeValue(Writer w, Object value)
throws IOException, JsonGenerationException, JsonMappingException
{
- _configAndWriteValue(createGenerator(w), value);
+ _writeValue(createGenerator(w), value);
}
/**
@@ -1064,7 +1062,7 @@ public class ObjectWriter
public void writeValue(DataOutput out, Object value)
throws IOException
{
- _configAndWriteValue(createGenerator(out), value);
+ _writeValue(createGenerator(out), value);
}
/**
@@ -1082,7 +1080,7 @@ public class ObjectWriter
// alas, we have to pull the recycler directly here...
SegmentedStringWriter sw = new SegmentedStringWriter(_generatorFactory._getBufferRecycler());
try {
- _configAndWriteValue(createGenerator(sw), value);
+ _writeValue(createGenerator(sw), value);
} catch (JsonProcessingException e) {
throw e;
} catch (IOException e) { // shouldn't really happen, but is declared as possibility so:
@@ -1106,7 +1104,7 @@ public class ObjectWriter
{
ByteArrayBuilder bb = new ByteArrayBuilder(_generatorFactory._getBufferRecycler());
try {
- _configAndWriteValue(createGenerator(bb, JsonEncoding.UTF8), value);
+ _writeValue(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:
@@ -1204,9 +1202,8 @@ public class ObjectWriter
* Method called to configure the generator as necessary and then
* call write functionality
*/
- protected final void _configAndWriteValue(JsonGenerator gen, Object value) throws IOException
+ protected final void _writeValue(JsonGenerator gen, Object value) throws IOException
{
- _configureGenerator(gen);
if (_config.isEnabled(SerializationFeature.CLOSE_CLOSEABLE) && (value instanceof Closeable)) {
_writeCloseable(gen, value);
return;
@@ -1246,12 +1243,13 @@ public class ObjectWriter
*
* @since 2.5
*/
- protected final void _configureGenerator(JsonGenerator gen)
+ protected final JsonGenerator _configureGenerator(JsonGenerator gen)
{
// order is slightly significant: both may change PrettyPrinter
// settings.
_config.initialize(gen); // since 2.5
_generatorSettings.initialize(gen);
+ return gen;
}
protected final void _assertNotNull(String paramName, Object src) {