Skip to content

Commit

Permalink
Merge branch '2.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 15, 2019
2 parents 8b279da + 851a379 commit 62af537
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 101 deletions.
6 changes: 5 additions & 1 deletion release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
69 changes: 31 additions & 38 deletions src/main/java/com/fasterxml/jackson/core/JsonGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,35 +373,31 @@ public void setSchema(FormatSchema schema) {

/**
* Method for writing start marker of an Array value, similar
* to {@link #writeStartArray()}, but also specifying how many
* elements will be written for the array before calling
* {@link #writeEndArray()}.
*<p>
* Default implementation simply calls {@link #writeStartArray()}.
*
* @param size Number of elements this array will have: actual
* number of values written (before matching call to
* {@link #writeEndArray()} MUST match; generator MAY verify
* this is the case.
* to {@link #writeStartArray()}, but also specifying what is the
* Java object that the Array Object being written represents (if any);
* {@code null} may be passed if not known or not applicable.
* This value is accessible from context as "current value"
*
* @param currentValue Java Object that Array being written represents, if any
* (or {@code null} if not known or not applicable)
*/
public void writeStartArray(int size) throws IOException {
writeStartArray();
}
public abstract void writeStartArray(Object currentValue) throws IOException;

/**
* Method for writing start marker of an Array value, similar
* to {@link #writeStartArray()}, but also specifying how many
* elements will be written for the array before calling
* to {@link #writeStartArray()}, but also specifying what is the
* Java object that the Array Object being written represents (if any)
* and how many elements will be written for the array before calling
* {@link #writeEndArray()}.
*<p>
* Default implementation simply calls {@link #writeStartArray()}.
*
* @param currentValue Java Object that Array being written represents, if any
* (or {@code null} if not known or not applicable)
* @param size Number of elements this array will have: actual
* number of values written (before matching call to
* {@link #writeEndArray()} MUST match; generator MAY verify
* this is the case.
*/
public abstract void writeStartArray(Object forValue, int size) throws IOException;
public abstract void writeStartArray(Object currentValue, int size) throws IOException;

/**
* Method for writing closing marker of a JSON Array value
Expand Down Expand Up @@ -434,8 +430,11 @@ public void writeStartArray(int size) throws IOException {
* Object values can be written in any context where values
* are allowed: meaning everywhere except for when
* a field name is expected.
*
* @param currentValue Java Object that Object being written represents, if any
* (or {@code null} if not known or not applicable)
*/
public abstract void writeStartObject(Object forValue) throws IOException;
public abstract void writeStartObject(Object currentValue) throws IOException;

/**
* Method for writing starting marker of an Object value
Expand All @@ -451,11 +450,7 @@ public void writeStartArray(int size) throws IOException {
* are allowed: meaning everywhere except for when
* a field name is expected.
*/
public void writeStartObject(Object forValue, int size) throws IOException
{
writeStartObject();
setCurrentValue(forValue);
}
public abstract void writeStartObject(Object forValue, int size) throws IOException;

/**
* Method for writing closing marker of an Object value
Expand Down Expand Up @@ -501,9 +496,7 @@ public void writeStartObject(Object forValue, int size) throws IOException
* Default implementation will simply convert id into <code>String</code>
* and call {@link #writeFieldName(String)}.
*/
public void writeFieldId(long id) throws IOException {
writeFieldName(Long.toString(id));
}
public abstract void writeFieldId(long id) throws IOException;

/*
/**********************************************************************
Expand Down Expand Up @@ -1209,7 +1202,7 @@ public void writeStringField(String fieldName, String value) throws IOException
* writeBoolean(value);
*</pre>
*/
public final void writeBooleanField(String fieldName, boolean value) throws IOException {
public void writeBooleanField(String fieldName, boolean value) throws IOException {
writeFieldName(fieldName);
writeBoolean(value);
}
Expand All @@ -1222,7 +1215,7 @@ public final void writeBooleanField(String fieldName, boolean value) throws IOEx
* writeNull();
*</pre>
*/
public final void writeNullField(String fieldName) throws IOException {
public void writeNullField(String fieldName) throws IOException {
writeFieldName(fieldName);
writeNull();
}
Expand All @@ -1235,7 +1228,7 @@ public final void writeNullField(String fieldName) throws IOException {
* writeNumber(value);
*</pre>
*/
public final void writeNumberField(String fieldName, int value) throws IOException {
public void writeNumberField(String fieldName, int value) throws IOException {
writeFieldName(fieldName);
writeNumber(value);
}
Expand All @@ -1248,7 +1241,7 @@ public final void writeNumberField(String fieldName, int value) throws IOExcepti
* writeNumber(value);
*</pre>
*/
public final void writeNumberField(String fieldName, long value) throws IOException {
public void writeNumberField(String fieldName, long value) throws IOException {
writeFieldName(fieldName);
writeNumber(value);
}
Expand All @@ -1261,7 +1254,7 @@ public final void writeNumberField(String fieldName, long value) throws IOExcept
* writeNumber(value);
*</pre>
*/
public final void writeNumberField(String fieldName, double value) throws IOException {
public void writeNumberField(String fieldName, double value) throws IOException {
writeFieldName(fieldName);
writeNumber(value);
}
Expand All @@ -1274,7 +1267,7 @@ public final void writeNumberField(String fieldName, double value) throws IOExce
* writeNumber(value);
*</pre>
*/
public final void writeNumberField(String fieldName, float value) throws IOException {
public void writeNumberField(String fieldName, float value) throws IOException {
writeFieldName(fieldName);
writeNumber(value);
}
Expand All @@ -1288,7 +1281,7 @@ public final void writeNumberField(String fieldName, float value) throws IOExcep
* writeNumber(value);
*</pre>
*/
public final void writeNumberField(String fieldName, BigDecimal value) throws IOException {
public void writeNumberField(String fieldName, BigDecimal value) throws IOException {
writeFieldName(fieldName);
writeNumber(value);
}
Expand All @@ -1302,7 +1295,7 @@ public final void writeNumberField(String fieldName, BigDecimal value) throws IO
* writeBinary(value);
*</pre>
*/
public final void writeBinaryField(String fieldName, byte[] data) throws IOException {
public void writeBinaryField(String fieldName, byte[] data) throws IOException {
writeFieldName(fieldName);
writeBinary(data);
}
Expand All @@ -1320,7 +1313,7 @@ public final void writeBinaryField(String fieldName, byte[] data) throws IOExcep
* (by calling {#link #writeEndArray}) after writing all values
* of the value Array.
*/
public final void writeArrayFieldStart(String fieldName) throws IOException {
public void writeArrayFieldStart(String fieldName) throws IOException {
writeFieldName(fieldName);
writeStartArray();
}
Expand All @@ -1338,7 +1331,7 @@ public final void writeArrayFieldStart(String fieldName) throws IOException {
* (by calling {#link #writeEndObject}) after writing all
* entries of the value Object.
*/
public final void writeObjectFieldStart(String fieldName) throws IOException {
public void writeObjectFieldStart(String fieldName) throws IOException {
writeFieldName(fieldName);
writeStartObject();
}
Expand All @@ -1352,7 +1345,7 @@ public final void writeObjectFieldStart(String fieldName) throws IOException {
* writeObject(pojo);
*</pre>
*/
public final void writeObjectField(String fieldName, Object pojo) throws IOException {
public void writeObjectField(String fieldName, Object pojo) throws IOException {
writeFieldName(fieldName);
writeObject(pojo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,58 +135,87 @@ public void writeStartArray() throws IOException
{
// First things first: whole-sale skipping easy
if (_itemFilter == null) {
_filterContext = _filterContext.createChildArrayContext(null, false);
_filterContext = _filterContext.createChildArrayContext(null, null, false);
return;
}
if (_itemFilter == TokenFilter.INCLUDE_ALL) { // include the whole sub-tree?
_filterContext = _filterContext.createChildArrayContext(_itemFilter, true);
_filterContext = _filterContext.createChildArrayContext(_itemFilter, null, true);
delegate.writeStartArray();
return;
}
// Ok; regular checking state then
_itemFilter = _filterContext.checkValue(_itemFilter);
if (_itemFilter == null) {
_filterContext = _filterContext.createChildArrayContext(null, false);
_filterContext = _filterContext.createChildArrayContext(null, null, false);
return;
}
if (_itemFilter != TokenFilter.INCLUDE_ALL) {
_itemFilter = _itemFilter.filterStartArray();
}
if (_itemFilter == TokenFilter.INCLUDE_ALL) {
_checkParentPath();
_filterContext = _filterContext.createChildArrayContext(_itemFilter, true);
_filterContext = _filterContext.createChildArrayContext(_itemFilter, null, true);
delegate.writeStartArray();
} else {
_filterContext = _filterContext.createChildArrayContext(_itemFilter, false);
_filterContext = _filterContext.createChildArrayContext(_itemFilter, null, false);
}
}


@Override
public void writeStartArray(Object currValue) throws IOException
{
if (_itemFilter == null) {
_filterContext = _filterContext.createChildArrayContext(null, currValue, false);
return;
}
if (_itemFilter == TokenFilter.INCLUDE_ALL) {
_filterContext = _filterContext.createChildArrayContext(_itemFilter, currValue, true);
delegate.writeStartArray(currValue);
return;
}
_itemFilter = _filterContext.checkValue(_itemFilter);
if (_itemFilter == null) {
_filterContext = _filterContext.createChildArrayContext(null, currValue, false);
return;
}
if (_itemFilter != TokenFilter.INCLUDE_ALL) {
_itemFilter = _itemFilter.filterStartArray();
}
if (_itemFilter == TokenFilter.INCLUDE_ALL) {
_checkParentPath();
_filterContext = _filterContext.createChildArrayContext(_itemFilter, currValue, true);
delegate.writeStartArray(currValue);
} else {
_filterContext = _filterContext.createChildArrayContext(_itemFilter, currValue, false);
}
}

@Override
public void writeStartArray(int size) throws IOException
public void writeStartArray(Object currValue, int size) throws IOException
{
if (_itemFilter == null) {
_filterContext = _filterContext.createChildArrayContext(null, false);
_filterContext = _filterContext.createChildArrayContext(null, currValue, false);
return;
}
if (_itemFilter == TokenFilter.INCLUDE_ALL) {
_filterContext = _filterContext.createChildArrayContext(_itemFilter, true);
delegate.writeStartArray(size);
_filterContext = _filterContext.createChildArrayContext(_itemFilter, currValue, true);
delegate.writeStartArray(currValue, size);
return;
}
_itemFilter = _filterContext.checkValue(_itemFilter);
if (_itemFilter == null) {
_filterContext = _filterContext.createChildArrayContext(null, false);
_filterContext = _filterContext.createChildArrayContext(null, currValue, false);
return;
}
if (_itemFilter != TokenFilter.INCLUDE_ALL) {
_itemFilter = _itemFilter.filterStartArray();
}
if (_itemFilter == TokenFilter.INCLUDE_ALL) {
_checkParentPath();
_filterContext = _filterContext.createChildArrayContext(_itemFilter, true);
delegate.writeStartArray(size);
_filterContext = _filterContext.createChildArrayContext(_itemFilter, currValue, true);
delegate.writeStartArray(currValue, size);
} else {
_filterContext = _filterContext.createChildArrayContext(_itemFilter, false);
_filterContext = _filterContext.createChildArrayContext(_itemFilter, currValue, false);
}
}

Expand All @@ -204,11 +233,11 @@ public void writeEndArray() throws IOException
public void writeStartObject() throws IOException
{
if (_itemFilter == null) {
_filterContext = _filterContext.createChildObjectContext(_itemFilter, false);
_filterContext = _filterContext.createChildObjectContext(_itemFilter, null, false);
return;
}
if (_itemFilter == TokenFilter.INCLUDE_ALL) {
_filterContext = _filterContext.createChildObjectContext(_itemFilter, true);
_filterContext = _filterContext.createChildObjectContext(_itemFilter, null, true);
delegate.writeStartObject();
return;
}
Expand All @@ -223,23 +252,53 @@ public void writeStartObject() throws IOException
}
if (f == TokenFilter.INCLUDE_ALL) {
_checkParentPath();
_filterContext = _filterContext.createChildObjectContext(f, true);
_filterContext = _filterContext.createChildObjectContext(f, null, true);
delegate.writeStartObject();
} else { // filter out
_filterContext = _filterContext.createChildObjectContext(f, false);
_filterContext = _filterContext.createChildObjectContext(f, null, false);
}
}


@Override
public void writeStartObject(Object currValue) throws IOException
{
if (_itemFilter == null) {
_filterContext = _filterContext.createChildObjectContext(_itemFilter, currValue, false);
return;
}
if (_itemFilter == TokenFilter.INCLUDE_ALL) {
_filterContext = _filterContext.createChildObjectContext(_itemFilter, currValue, true);
delegate.writeStartObject(currValue);
return;
}

TokenFilter f = _filterContext.checkValue(_itemFilter);
if (f == null) {
return;
}

if (f != TokenFilter.INCLUDE_ALL) {
f = f.filterStartObject();
}
if (f == TokenFilter.INCLUDE_ALL) {
_checkParentPath();
_filterContext = _filterContext.createChildObjectContext(f, currValue, true);
delegate.writeStartObject(currValue);
} else { // filter out
_filterContext = _filterContext.createChildObjectContext(f, currValue, false);
}
}

@Override
public void writeStartObject(Object forValue) throws IOException
public void writeStartObject(Object currValue, int size) throws IOException
{
if (_itemFilter == null) {
_filterContext = _filterContext.createChildObjectContext(_itemFilter, false);
_filterContext = _filterContext.createChildObjectContext(_itemFilter, currValue, false);
return;
}
if (_itemFilter == TokenFilter.INCLUDE_ALL) {
_filterContext = _filterContext.createChildObjectContext(_itemFilter, true);
delegate.writeStartObject(forValue);
_filterContext = _filterContext.createChildObjectContext(_itemFilter, currValue, true);
delegate.writeStartObject(currValue, size);
return;
}

Expand All @@ -253,10 +312,10 @@ public void writeStartObject(Object forValue) throws IOException
}
if (f == TokenFilter.INCLUDE_ALL) {
_checkParentPath();
_filterContext = _filterContext.createChildObjectContext(f, true);
delegate.writeStartObject(forValue);
_filterContext = _filterContext.createChildObjectContext(f, currValue, true);
delegate.writeStartObject(currValue, size);
} else { // filter out
_filterContext = _filterContext.createChildObjectContext(f, false);
_filterContext = _filterContext.createChildObjectContext(f, currValue, false);
}
}

Expand Down
Loading

0 comments on commit 62af537

Please sign in to comment.