From 851a3792e7877710112f86f5d9f0688f2367dcc1 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Thu, 15 Aug 2019 09:57:26 -0700 Subject: [PATCH] Fix #517 --- release-notes/VERSION-2.x | 6 +++++- .../fasterxml/jackson/core/JsonGenerator.java | 19 ++++++++++++++++++- .../core/util/JsonGeneratorDelegate.java | 6 ++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 90366a5fac..2f06f9e017 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -14,6 +14,11 @@ JSON library. === Releases === ------------------------------------------------------------------------ +2.10.0.pr2 + +#517: Add `JsonGenerator.writeStartObject(Object, int)` (needed by CBOR, maybe Avro) +#549: Add configurability of "quote character" for JSON factory + 2.10.0.pr1 (19-Jul-2019) #433: Add Builder pattern for creating configured Stream factories @@ -39,7 +44,6 @@ JSON library. (reported by Alex R) #548: ByteQuadsCanonicalizer: ArrayIndexOutOfBoundsException in addName (reported by Alex R) -#549: Add configurability of "quote character" for JSON factory 2.9.10 (not yet released) diff --git a/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java b/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java index e89b5d148d..81726ccd2c 100644 --- a/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java +++ b/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java @@ -725,6 +725,7 @@ public void setCurrentValue(Object v) { */ public abstract void writeStartArray() throws IOException; + // TODO: deprecate in 2.11 (remove from 3.0) /** * Method for writing start marker of an Array value, similar * to {@link #writeStartArray()}, but also specifying how many @@ -743,7 +744,23 @@ public void setCurrentValue(Object v) { public void writeStartArray(int size) throws IOException { writeStartArray(); } - + + /** + * @since 2.10 + */ + public void writeStartArray(Object forValue) throws IOException { + writeStartArray(); + setCurrentValue(forValue); + } + + /** + * @since 2.10 + */ + public void writeStartArray(Object forValue, int size) throws IOException { + writeStartArray(size); + setCurrentValue(forValue); + } + /** * Method for writing closing marker of a JSON Array value * (character ']'; plus possible white space decoration 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 3b985a18bb..3e1e04bd5c 100644 --- a/src/main/java/com/fasterxml/jackson/core/util/JsonGeneratorDelegate.java +++ b/src/main/java/com/fasterxml/jackson/core/util/JsonGeneratorDelegate.java @@ -196,6 +196,12 @@ public JsonGenerator setPrettyPrinter(PrettyPrinter pp) { @Override public void writeStartArray(int size) throws IOException { delegate.writeStartArray(size); } + @Override + public void writeStartArray(Object forValue) throws IOException { delegate.writeStartArray(forValue); } + + @Override + public void writeStartArray(Object forValue, int size) throws IOException { delegate.writeStartArray(forValue, size); } + @Override public void writeEndArray() throws IOException { delegate.writeEndArray(); }