diff --git a/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java b/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java index c6c929927f..415652382e 100644 --- a/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java +++ b/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java @@ -410,8 +410,8 @@ public Object getOutputTarget() { * @since 2.13 (added as replacement for older {@link #getCurrentValue()} */ public Object currentValue() { - // TODO: implement directly in 2.14 or later, make getCurrentValue() call this - return getCurrentValue(); + JsonStreamContext ctxt = getOutputContext(); + return (ctxt == null) ? null : ctxt.getCurrentValue(); } /** @@ -425,20 +425,23 @@ public Object currentValue() { * @since 2.13 (added as replacement for older {@link #setCurrentValue} */ public void assignCurrentValue(Object v) { - // TODO: implement directly in 2.14 or later, make setCurrentValue() call this - setCurrentValue(v); + JsonStreamContext ctxt = getOutputContext(); + if (ctxt != null) { + ctxt.setCurrentValue(v); + } } - // TODO: deprecate in 2.14 or later /** * Alias for {@link #currentValue()}, to be deprecated in later * Jackson 2.x versions (and removed from Jackson 3.0). * * @return Location of the last processed input unit (byte or character) + * + * @deprecated Since 2.17 use {@link #currentValue()} instead */ + @Deprecated public Object getCurrentValue() { - JsonStreamContext ctxt = getOutputContext(); - return (ctxt == null) ? null : ctxt.getCurrentValue(); + return currentValue(); } // TODO: deprecate in 2.14 or later @@ -447,12 +450,12 @@ public Object getCurrentValue() { * Jackson 2.x versions (and removed from Jackson 3.0). * * @param v Current value to assign for the current context of this generator + * + * @deprecated Since 2.17 use {@link #currentValue()} instead */ + @Deprecated public void setCurrentValue(Object v) { - JsonStreamContext ctxt = getOutputContext(); - if (ctxt != null) { - ctxt.setCurrentValue(v); - } + assignCurrentValue(v); } /* diff --git a/src/main/java/com/fasterxml/jackson/core/base/GeneratorBase.java b/src/main/java/com/fasterxml/jackson/core/base/GeneratorBase.java index 75b87d2539..9f37a94522 100644 --- a/src/main/java/com/fasterxml/jackson/core/base/GeneratorBase.java +++ b/src/main/java/com/fasterxml/jackson/core/base/GeneratorBase.java @@ -151,12 +151,12 @@ protected GeneratorBase(int features, ObjectCodec codec, IOContext ioContext, Js @Override public Version version() { return PackageVersion.VERSION; } @Override - public Object getCurrentValue() { + public Object currentValue() { return _writeContext.getCurrentValue(); } @Override - public void setCurrentValue(Object v) { + public void assignCurrentValue(Object v) { if (_writeContext != null) { _writeContext.setCurrentValue(v); } @@ -312,7 +312,7 @@ public void writeStartObject(Object forValue) throws IOException { writeStartObject(); if (forValue != null) { - setCurrentValue(forValue); + assignCurrentValue(forValue); } } diff --git a/src/main/java/com/fasterxml/jackson/core/util/JsonGeneratorDelegate.java b/src/main/java/com/fasterxml/jackson/core/util/JsonGeneratorDelegate.java index 5879063d62..aec751e7ff 100644 --- a/src/main/java/com/fasterxml/jackson/core/util/JsonGeneratorDelegate.java +++ b/src/main/java/com/fasterxml/jackson/core/util/JsonGeneratorDelegate.java @@ -66,11 +66,11 @@ public JsonGeneratorDelegate(JsonGenerator d, boolean delegateCopyMethods) { @Override public void assignCurrentValue(Object v) { delegate.assignCurrentValue(v); } @Override public Object currentValue() { return delegate.currentValue(); } - // TODO: deprecate in 2.14 or later + @Deprecated // since 2.17 @Override public void setCurrentValue(Object v) { delegate.setCurrentValue(v); } - // TODO: deprecate in 2.14 or later + @Deprecated // since 2.17 @Override public Object getCurrentValue() { return delegate.getCurrentValue(); } diff --git a/src/test/java/com/fasterxml/jackson/core/util/TestDelegates.java b/src/test/java/com/fasterxml/jackson/core/util/TestDelegates.java index c7290c2744..1cdc1e9ec6 100644 --- a/src/test/java/com/fasterxml/jackson/core/util/TestDelegates.java +++ b/src/test/java/com/fasterxml/jackson/core/util/TestDelegates.java @@ -376,7 +376,7 @@ public void testGeneratorDelegateArrays() throws IOException final Object MARKER = new Object(); del.writeStartArray(MARKER); - assertSame(MARKER, del.getCurrentValue()); + assertSame(MARKER, del.currentValue()); del.writeArray(new int[] { 1, 2, 3 }, 0, 3); del.writeArray(new long[] { 1, 123456, 2 }, 1, 1); @@ -397,7 +397,7 @@ public void testGeneratorDelegateComments() throws IOException final Object MARKER = new Object(); del.writeStartArray(MARKER, 5); - assertSame(MARKER, del.getCurrentValue()); + assertSame(MARKER, del.currentValue()); del.writeNumber((short) 1); del.writeNumber(12L);