Fix botched merge
diff --git a/pom.xml b/pom.xml
index 0ba47e4..86245fb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<name>Jackson-core</name>
- <version>2.7.4-SNAPSHOT</version>
+ <version>2.8.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<description>Core Jackson abstractions, basic JSON streaming API implementation</description>
<inceptionYear>2008</inceptionYear>
@@ -23,7 +23,7 @@
</scm>
<properties>
- <!-- 02-Oct-2015, tatu: Retain Java6/JDK1.6 compatibility for streaming for Jackson 2.7 -->
+ <!-- 03-Feb-2016, tatu: Retain Java6/JDK1.6 compatibility for streaming for Jackson 2.8 -->
<javac.src.version>1.6</javac.src.version>
<javac.target.version>1.6</javac.target.version>
@@ -103,8 +103,7 @@
<encoding>UTF-8</encoding>
<maxmemory>1g</maxmemory>
<links>
- <!-- JDK, other Jackson pkgs -->
- <link>http://docs.oracle.com/javase/6/docs/api/</link>
+ <link>http://docs.oracle.com/javase/7/docs/api/</link>
</links>
<excludePackageNames>${javadoc.package.exclude}</excludePackageNames>
<bootclasspath>${sun.boot.class.path}</bootclasspath>
diff --git a/release-notes/VERSION b/release-notes/VERSION
index be7a2d0..95b4302 100644
--- a/release-notes/VERSION
+++ b/release-notes/VERSION
@@ -14,6 +14,13 @@
=== Releases ===
------------------------------------------------------------------------
+2.8.0 (not yet released)
+
+#253: Add `JsonGenerator. writeEmbeddedObject()` to allow writes of opaque native types
+ (suggested by Gregoire C)
+#255: Relax ownership checks for buffers not to require increase in size
+#257: Add `writeStartObject(Object pojo)` to streamline assignment of current value
+
2.7.4 (not yet released)
#209: Make use of `_allowMultipleMatches` in `FilteringParserDelegate`
diff --git a/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java b/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java
index 09704a4..80d5f91 100644
--- a/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java
+++ b/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java
@@ -756,6 +756,26 @@
public abstract void writeStartObject() throws IOException;
/**
+ * Method for writing starting marker of a JSON Object value
+ * (character '{'; plus possible white space decoration
+ * if pretty-printing is enabled), to represent Java given
+ * as the argument. Argument is offered as metadata, but more
+ * importantly it should be assigned as the "current value"
+ * for the Object content that gets constructed and initialized.
+ *<p>
+ * Object values can be written in any context where values
+ * are allowed: meaning everywhere except for when
+ * a field name is expected.
+ *
+ * @since 2.8.
+ */
+ public void writeStartObject(Object forValue) throws IOException
+ {
+ writeStartObject();
+ setCurrentValue(forValue);
+ }
+
+ /**
* Method for writing closing marker of a JSON Object value
* (character '}'; plus possible white space decoration
* if pretty-printing is enabled).
@@ -1236,6 +1256,17 @@
throw new JsonGenerationException("No native support for writing Type Ids", this);
}
+ /**
+ * Method that can be called on backends that support passing opaque datatypes of
+ * non-JSON formats
+ *
+ * @since 2.8
+ */
+ public void writeEmbeddedObject(Object object) throws IOException {
+ throw new JsonGenerationException("No native support for writing embedded objects",
+ this);
+ }
+
/*
/**********************************************************
/* Public API, write methods, serializing Java objects
diff --git a/src/main/java/com/fasterxml/jackson/core/ObjectCodec.java b/src/main/java/com/fasterxml/jackson/core/ObjectCodec.java
index 649c89f..afa6aaa 100644
--- a/src/main/java/com/fasterxml/jackson/core/ObjectCodec.java
+++ b/src/main/java/com/fasterxml/jackson/core/ObjectCodec.java
@@ -26,9 +26,9 @@
{
protected ObjectCodec() { }
- // Since 2.3: need baseline implementation to avoid backwards compatibility
+ // Since 2.3
@Override
- public Version version() { return Version.unknownVersion(); }
+ public abstract Version version();
/*
/**********************************************************
@@ -46,8 +46,8 @@
* The reason is that due to type erasure, key and value types
* can not be introspected when using this method.
*/
- public abstract <T> T readValue(JsonParser jp, Class<T> valueType)
- throws IOException, JsonProcessingException;
+ public abstract <T> T readValue(JsonParser p, Class<T> valueType)
+ throws IOException;
/**
* Method to deserialize JSON content into a Java type, reference
@@ -56,8 +56,8 @@
* and specifically needs to be used if the root type is a
* parameterized (generic) container type.
*/
- public abstract <T> T readValue(JsonParser jp, TypeReference<?> valueTypeRef)
- throws IOException, JsonProcessingException;
+ public abstract <T> T readValue(JsonParser p, TypeReference<?> valueTypeRef)
+ throws IOException;
/**
* Method to deserialize JSON content into a POJO, type specified
@@ -65,30 +65,30 @@
* including containers like {@link java.util.Collection} and
* {@link java.util.Map}).
*/
- public abstract <T> T readValue(JsonParser jp, ResolvedType valueType)
- throws IOException, JsonProcessingException;
+ public abstract <T> T readValue(JsonParser p, ResolvedType valueType)
+ throws IOException;
/**
* Method for reading sequence of Objects from parser stream,
* all with same specified value type.
*/
- public abstract <T> Iterator<T> readValues(JsonParser jp, Class<T> valueType)
- throws IOException, JsonProcessingException;
+ public abstract <T> Iterator<T> readValues(JsonParser p, Class<T> valueType)
+ throws IOException;
/**
* Method for reading sequence of Objects from parser stream,
* all with same specified value type.
*/
- public abstract <T> Iterator<T> readValues(JsonParser jp, TypeReference<?> valueTypeRef)
- throws IOException, JsonProcessingException;
+ public abstract <T> Iterator<T> readValues(JsonParser p, TypeReference<?> valueTypeRef)
+ throws IOException;
/**
* Method for reading sequence of Objects from parser stream,
* all with same specified value type.
*/
- public abstract <T> Iterator<T> readValues(JsonParser jp, ResolvedType valueType)
- throws IOException, JsonProcessingException;
-
+ public abstract <T> Iterator<T> readValues(JsonParser p, ResolvedType valueType)
+ throws IOException;
+
/*
/**********************************************************
/* API for serialization (Object-to-JSON)
@@ -99,8 +99,7 @@
* Method to serialize given Java Object, using generator
* provided.
*/
- public abstract void writeValue(JsonGenerator jgen, Object value)
- throws IOException, JsonProcessingException;
+ public abstract void writeValue(JsonGenerator gen, Object value) throws IOException;
/*
/**********************************************************
@@ -116,15 +115,13 @@
* value event, not container). Empty or whitespace
* documents return null.
*
- * @return next tree from jp, or null if empty.
+ * @return next tree from p, or null if empty.
*/
@Override
- public abstract <T extends TreeNode> T readTree(JsonParser jp)
- throws IOException, JsonProcessingException;
+ public abstract <T extends TreeNode> T readTree(JsonParser p) throws IOException;
@Override
- public abstract void writeTree(JsonGenerator jg, TreeNode tree)
- throws IOException, JsonProcessingException;
+ public abstract void writeTree(JsonGenerator gen, TreeNode tree) throws IOException;
/**
* Method for construct root level Object nodes
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 c99832b..b35916b 100644
--- a/src/main/java/com/fasterxml/jackson/core/base/GeneratorBase.java
+++ b/src/main/java/com/fasterxml/jackson/core/base/GeneratorBase.java
@@ -266,6 +266,16 @@
//public void writeStartObject() throws IOException
//public void writeEndObject() throws IOException
+ @Override // since 2.8
+ public void writeStartObject(Object forValue) throws IOException
+ {
+ writeStartObject();
+ if ((_writeContext != null) && (forValue != null)) {
+ _writeContext.setCurrentValue(forValue);
+ }
+ setCurrentValue(forValue);
+ }
+
/*
/**********************************************************
/* Public API, write methods, textual
diff --git a/src/main/java/com/fasterxml/jackson/core/io/IOContext.java b/src/main/java/com/fasterxml/jackson/core/io/IOContext.java
index a4675be..18f50c8 100644
--- a/src/main/java/com/fasterxml/jackson/core/io/IOContext.java
+++ b/src/main/java/com/fasterxml/jackson/core/io/IOContext.java
@@ -270,12 +270,17 @@
}
protected final void _verifyRelease(byte[] toRelease, byte[] src) {
- if ((toRelease != src) && (toRelease.length <= src.length)) { throw wrongBuf(); }
+ // 07-Mar-2016, tatu: As per [core#255], only prevent shrinking of buffer
+ if ((toRelease != src) && (toRelease.length < src.length)) { throw wrongBuf(); }
}
protected final void _verifyRelease(char[] toRelease, char[] src) {
- if ((toRelease != src) && (toRelease.length <= src.length)) { throw wrongBuf(); }
+ // 07-Mar-2016, tatu: As per [core#255], only prevent shrinking of buffer
+ if ((toRelease != src) && (toRelease.length < src.length)) { throw wrongBuf(); }
}
- private IllegalArgumentException wrongBuf() { return new IllegalArgumentException("Trying to release buffer not owned by the context"); }
+ private IllegalArgumentException wrongBuf() {
+ // sanity check failed; trying to return different, smaller buffer.
+ return new IllegalArgumentException("Trying to release buffer smaller than original");
+ }
}
diff --git a/src/main/java/com/fasterxml/jackson/core/json/UTF8JsonGenerator.java b/src/main/java/com/fasterxml/jackson/core/json/UTF8JsonGenerator.java
index 8f17ea3..d5a33fe 100644
--- a/src/main/java/com/fasterxml/jackson/core/json/UTF8JsonGenerator.java
+++ b/src/main/java/com/fasterxml/jackson/core/json/UTF8JsonGenerator.java
@@ -309,6 +309,25 @@
}
}
+ @Override // since 2.8
+ public void writeStartObject(Object forValue) throws IOException
+ {
+ _verifyValueWrite("start an object");
+ JsonWriteContext ctxt = _writeContext.createChildObjectContext();
+ _writeContext = ctxt;
+ if (forValue != null) {
+ ctxt.setCurrentValue(forValue);
+ }
+ if (_cfgPrettyPrinter != null) {
+ _cfgPrettyPrinter.writeStartObject(this);
+ } else {
+ if (_outputTail >= _outputEnd) {
+ _flushBuffer();
+ }
+ _outputBuffer[_outputTail++] = '{';
+ }
+ }
+
@Override
public final void writeEndObject() throws IOException
{
diff --git a/src/main/java/com/fasterxml/jackson/core/json/WriterBasedJsonGenerator.java b/src/main/java/com/fasterxml/jackson/core/json/WriterBasedJsonGenerator.java
index 316886b..6e5b9ff 100644
--- a/src/main/java/com/fasterxml/jackson/core/json/WriterBasedJsonGenerator.java
+++ b/src/main/java/com/fasterxml/jackson/core/json/WriterBasedJsonGenerator.java
@@ -195,7 +195,7 @@
*/
@Override
- public void writeStartArray() throws IOException, JsonGenerationException
+ public void writeStartArray() throws IOException
{
_verifyValueWrite("start an array");
_writeContext = _writeContext.createChildArrayContext();
@@ -210,7 +210,7 @@
}
@Override
- public void writeEndArray() throws IOException, JsonGenerationException
+ public void writeEndArray() throws IOException
{
if (!_writeContext.inArray()) {
_reportError("Current context not an ARRAY but "+_writeContext.getTypeDesc());
@@ -226,8 +226,27 @@
_writeContext = _writeContext.clearAndGetParent();
}
+ @Override // since 2.8
+ public void writeStartObject(Object forValue) throws IOException
+ {
+ _verifyValueWrite("start an object");
+ JsonWriteContext ctxt = _writeContext.createChildObjectContext();
+ _writeContext = ctxt;
+ if (forValue != null) {
+ ctxt.setCurrentValue(forValue);
+ }
+ if (_cfgPrettyPrinter != null) {
+ _cfgPrettyPrinter.writeStartObject(this);
+ } else {
+ if (_outputTail >= _outputEnd) {
+ _flushBuffer();
+ }
+ _outputBuffer[_outputTail++] = '{';
+ }
+ }
+
@Override
- public void writeStartObject() throws IOException, JsonGenerationException
+ public void writeStartObject() throws IOException
{
_verifyValueWrite("start an object");
_writeContext = _writeContext.createChildObjectContext();
@@ -242,7 +261,7 @@
}
@Override
- public void writeEndObject() throws IOException, JsonGenerationException
+ public void writeEndObject() throws IOException
{
if (!_writeContext.inObject()) {
_reportError("Current context not an object but "+_writeContext.getTypeDesc());
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 f8c31ca..40cd508 100644
--- a/src/main/java/com/fasterxml/jackson/core/util/JsonGeneratorDelegate.java
+++ b/src/main/java/com/fasterxml/jackson/core/util/JsonGeneratorDelegate.java
@@ -200,6 +200,9 @@
@Override
public void writeStartObject() throws IOException { delegate.writeStartObject(); }
+
+ @Override
+ public void writeStartObject(Object forValue) throws IOException { delegate.writeStartObject(forValue); }
@Override
public void writeEndObject() throws IOException { delegate.writeEndObject(); }
@@ -326,6 +329,9 @@
@Override
public void writeTypeId(Object id) throws IOException { delegate.writeTypeId(id); }
+
+ @Override
+ public void writeEmbeddedObject(Object object) throws IOException { delegate.writeEmbeddedObject(object); }
/*
/**********************************************************
diff --git a/src/test/java/com/fasterxml/jackson/core/io/TestIOContext.java b/src/test/java/com/fasterxml/jackson/core/io/TestIOContext.java
index 3bad591..475abb5 100644
--- a/src/test/java/com/fasterxml/jackson/core/io/TestIOContext.java
+++ b/src/test/java/com/fasterxml/jackson/core/io/TestIOContext.java
@@ -24,7 +24,7 @@
try {
ctxt.releaseReadIOBuffer(new byte[1]);
} catch (IllegalArgumentException e) {
- verifyException(e, "not owned");
+ verifyException(e, "smaller than original");
}
// but call with null is a NOP for convenience
ctxt.releaseReadIOBuffer(null);
@@ -40,7 +40,7 @@
try {
ctxt.releaseWriteEncodingBuffer(new byte[1]);
} catch (IllegalArgumentException e) {
- verifyException(e, "not owned");
+ verifyException(e, "smaller than original");
}
ctxt.releaseWriteEncodingBuffer(null);
@@ -55,7 +55,7 @@
try {
ctxt.releaseTokenBuffer(new char[1]);
} catch (IllegalArgumentException e) {
- verifyException(e, "not owned");
+ verifyException(e, "smaller than original");
}
ctxt.releaseTokenBuffer(null);
@@ -70,7 +70,7 @@
try {
ctxt.releaseConcatBuffer(new char[1]);
} catch (IllegalArgumentException e) {
- verifyException(e, "not owned");
+ verifyException(e, "smaller than original");
}
ctxt.releaseConcatBuffer(null);
@@ -85,7 +85,7 @@
try {
ctxt.releaseNameCopyBuffer(new char[1]);
} catch (IllegalArgumentException e) {
- verifyException(e, "not owned");
+ verifyException(e, "smaller than original");
}
ctxt.releaseNameCopyBuffer(null);
}