Skip to content

Commit 62af537

Browse files
committed
Merge branch '2.10'
2 parents 8b279da + 851a379 commit 62af537

File tree

9 files changed

+218
-101
lines changed

9 files changed

+218
-101
lines changed

release-notes/VERSION-2.x

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ JSON library.
1414
=== Releases ===
1515
------------------------------------------------------------------------
1616

17+
2.10.0.pr2
18+
19+
#517: Add `JsonGenerator.writeStartObject(Object, int)` (needed by CBOR, maybe Avro)
20+
#549: Add configurability of "quote character" for JSON factory
21+
1722
2.10.0.pr1 (19-Jul-2019)
1823

1924
#433: Add Builder pattern for creating configured Stream factories
@@ -39,7 +44,6 @@ JSON library.
3944
(reported by Alex R)
4045
#548: ByteQuadsCanonicalizer: ArrayIndexOutOfBoundsException in addName
4146
(reported by Alex R)
42-
#549: Add configurability of "quote character" for JSON factory
4347

4448
2.9.10 (not yet released)
4549

src/main/java/com/fasterxml/jackson/core/JsonGenerator.java

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -373,35 +373,31 @@ public void setSchema(FormatSchema schema) {
373373

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

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

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

440439
/**
441440
* Method for writing starting marker of an Object value
@@ -451,11 +450,7 @@ public void writeStartArray(int size) throws IOException {
451450
* are allowed: meaning everywhere except for when
452451
* a field name is expected.
453452
*/
454-
public void writeStartObject(Object forValue, int size) throws IOException
455-
{
456-
writeStartObject();
457-
setCurrentValue(forValue);
458-
}
453+
public abstract void writeStartObject(Object forValue, int size) throws IOException;
459454

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

508501
/*
509502
/**********************************************************************
@@ -1209,7 +1202,7 @@ public void writeStringField(String fieldName, String value) throws IOException
12091202
* writeBoolean(value);
12101203
*</pre>
12111204
*/
1212-
public final void writeBooleanField(String fieldName, boolean value) throws IOException {
1205+
public void writeBooleanField(String fieldName, boolean value) throws IOException {
12131206
writeFieldName(fieldName);
12141207
writeBoolean(value);
12151208
}
@@ -1222,7 +1215,7 @@ public final void writeBooleanField(String fieldName, boolean value) throws IOEx
12221215
* writeNull();
12231216
*</pre>
12241217
*/
1225-
public final void writeNullField(String fieldName) throws IOException {
1218+
public void writeNullField(String fieldName) throws IOException {
12261219
writeFieldName(fieldName);
12271220
writeNull();
12281221
}
@@ -1235,7 +1228,7 @@ public final void writeNullField(String fieldName) throws IOException {
12351228
* writeNumber(value);
12361229
*</pre>
12371230
*/
1238-
public final void writeNumberField(String fieldName, int value) throws IOException {
1231+
public void writeNumberField(String fieldName, int value) throws IOException {
12391232
writeFieldName(fieldName);
12401233
writeNumber(value);
12411234
}
@@ -1248,7 +1241,7 @@ public final void writeNumberField(String fieldName, int value) throws IOExcepti
12481241
* writeNumber(value);
12491242
*</pre>
12501243
*/
1251-
public final void writeNumberField(String fieldName, long value) throws IOException {
1244+
public void writeNumberField(String fieldName, long value) throws IOException {
12521245
writeFieldName(fieldName);
12531246
writeNumber(value);
12541247
}
@@ -1261,7 +1254,7 @@ public final void writeNumberField(String fieldName, long value) throws IOExcept
12611254
* writeNumber(value);
12621255
*</pre>
12631256
*/
1264-
public final void writeNumberField(String fieldName, double value) throws IOException {
1257+
public void writeNumberField(String fieldName, double value) throws IOException {
12651258
writeFieldName(fieldName);
12661259
writeNumber(value);
12671260
}
@@ -1274,7 +1267,7 @@ public final void writeNumberField(String fieldName, double value) throws IOExce
12741267
* writeNumber(value);
12751268
*</pre>
12761269
*/
1277-
public final void writeNumberField(String fieldName, float value) throws IOException {
1270+
public void writeNumberField(String fieldName, float value) throws IOException {
12781271
writeFieldName(fieldName);
12791272
writeNumber(value);
12801273
}
@@ -1288,7 +1281,7 @@ public final void writeNumberField(String fieldName, float value) throws IOExcep
12881281
* writeNumber(value);
12891282
*</pre>
12901283
*/
1291-
public final void writeNumberField(String fieldName, BigDecimal value) throws IOException {
1284+
public void writeNumberField(String fieldName, BigDecimal value) throws IOException {
12921285
writeFieldName(fieldName);
12931286
writeNumber(value);
12941287
}
@@ -1302,7 +1295,7 @@ public final void writeNumberField(String fieldName, BigDecimal value) throws IO
13021295
* writeBinary(value);
13031296
*</pre>
13041297
*/
1305-
public final void writeBinaryField(String fieldName, byte[] data) throws IOException {
1298+
public void writeBinaryField(String fieldName, byte[] data) throws IOException {
13061299
writeFieldName(fieldName);
13071300
writeBinary(data);
13081301
}
@@ -1320,7 +1313,7 @@ public final void writeBinaryField(String fieldName, byte[] data) throws IOExcep
13201313
* (by calling {#link #writeEndArray}) after writing all values
13211314
* of the value Array.
13221315
*/
1323-
public final void writeArrayFieldStart(String fieldName) throws IOException {
1316+
public void writeArrayFieldStart(String fieldName) throws IOException {
13241317
writeFieldName(fieldName);
13251318
writeStartArray();
13261319
}
@@ -1338,7 +1331,7 @@ public final void writeArrayFieldStart(String fieldName) throws IOException {
13381331
* (by calling {#link #writeEndObject}) after writing all
13391332
* entries of the value Object.
13401333
*/
1341-
public final void writeObjectFieldStart(String fieldName) throws IOException {
1334+
public void writeObjectFieldStart(String fieldName) throws IOException {
13421335
writeFieldName(fieldName);
13431336
writeStartObject();
13441337
}
@@ -1352,7 +1345,7 @@ public final void writeObjectFieldStart(String fieldName) throws IOException {
13521345
* writeObject(pojo);
13531346
*</pre>
13541347
*/
1355-
public final void writeObjectField(String fieldName, Object pojo) throws IOException {
1348+
public void writeObjectField(String fieldName, Object pojo) throws IOException {
13561349
writeFieldName(fieldName);
13571350
writeObject(pojo);
13581351
}

src/main/java/com/fasterxml/jackson/core/filter/FilteringGeneratorDelegate.java

Lines changed: 85 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -135,58 +135,87 @@ public void writeStartArray() throws IOException
135135
{
136136
// First things first: whole-sale skipping easy
137137
if (_itemFilter == null) {
138-
_filterContext = _filterContext.createChildArrayContext(null, false);
138+
_filterContext = _filterContext.createChildArrayContext(null, null, false);
139139
return;
140140
}
141141
if (_itemFilter == TokenFilter.INCLUDE_ALL) { // include the whole sub-tree?
142-
_filterContext = _filterContext.createChildArrayContext(_itemFilter, true);
142+
_filterContext = _filterContext.createChildArrayContext(_itemFilter, null, true);
143143
delegate.writeStartArray();
144144
return;
145145
}
146146
// Ok; regular checking state then
147147
_itemFilter = _filterContext.checkValue(_itemFilter);
148148
if (_itemFilter == null) {
149-
_filterContext = _filterContext.createChildArrayContext(null, false);
149+
_filterContext = _filterContext.createChildArrayContext(null, null, false);
150150
return;
151151
}
152152
if (_itemFilter != TokenFilter.INCLUDE_ALL) {
153153
_itemFilter = _itemFilter.filterStartArray();
154154
}
155155
if (_itemFilter == TokenFilter.INCLUDE_ALL) {
156156
_checkParentPath();
157-
_filterContext = _filterContext.createChildArrayContext(_itemFilter, true);
157+
_filterContext = _filterContext.createChildArrayContext(_itemFilter, null, true);
158158
delegate.writeStartArray();
159159
} else {
160-
_filterContext = _filterContext.createChildArrayContext(_itemFilter, false);
160+
_filterContext = _filterContext.createChildArrayContext(_itemFilter, null, false);
161161
}
162162
}
163-
163+
164+
@Override
165+
public void writeStartArray(Object currValue) throws IOException
166+
{
167+
if (_itemFilter == null) {
168+
_filterContext = _filterContext.createChildArrayContext(null, currValue, false);
169+
return;
170+
}
171+
if (_itemFilter == TokenFilter.INCLUDE_ALL) {
172+
_filterContext = _filterContext.createChildArrayContext(_itemFilter, currValue, true);
173+
delegate.writeStartArray(currValue);
174+
return;
175+
}
176+
_itemFilter = _filterContext.checkValue(_itemFilter);
177+
if (_itemFilter == null) {
178+
_filterContext = _filterContext.createChildArrayContext(null, currValue, false);
179+
return;
180+
}
181+
if (_itemFilter != TokenFilter.INCLUDE_ALL) {
182+
_itemFilter = _itemFilter.filterStartArray();
183+
}
184+
if (_itemFilter == TokenFilter.INCLUDE_ALL) {
185+
_checkParentPath();
186+
_filterContext = _filterContext.createChildArrayContext(_itemFilter, currValue, true);
187+
delegate.writeStartArray(currValue);
188+
} else {
189+
_filterContext = _filterContext.createChildArrayContext(_itemFilter, currValue, false);
190+
}
191+
}
192+
164193
@Override
165-
public void writeStartArray(int size) throws IOException
194+
public void writeStartArray(Object currValue, int size) throws IOException
166195
{
167196
if (_itemFilter == null) {
168-
_filterContext = _filterContext.createChildArrayContext(null, false);
197+
_filterContext = _filterContext.createChildArrayContext(null, currValue, false);
169198
return;
170199
}
171200
if (_itemFilter == TokenFilter.INCLUDE_ALL) {
172-
_filterContext = _filterContext.createChildArrayContext(_itemFilter, true);
173-
delegate.writeStartArray(size);
201+
_filterContext = _filterContext.createChildArrayContext(_itemFilter, currValue, true);
202+
delegate.writeStartArray(currValue, size);
174203
return;
175204
}
176205
_itemFilter = _filterContext.checkValue(_itemFilter);
177206
if (_itemFilter == null) {
178-
_filterContext = _filterContext.createChildArrayContext(null, false);
207+
_filterContext = _filterContext.createChildArrayContext(null, currValue, false);
179208
return;
180209
}
181210
if (_itemFilter != TokenFilter.INCLUDE_ALL) {
182211
_itemFilter = _itemFilter.filterStartArray();
183212
}
184213
if (_itemFilter == TokenFilter.INCLUDE_ALL) {
185214
_checkParentPath();
186-
_filterContext = _filterContext.createChildArrayContext(_itemFilter, true);
187-
delegate.writeStartArray(size);
215+
_filterContext = _filterContext.createChildArrayContext(_itemFilter, currValue, true);
216+
delegate.writeStartArray(currValue, size);
188217
} else {
189-
_filterContext = _filterContext.createChildArrayContext(_itemFilter, false);
218+
_filterContext = _filterContext.createChildArrayContext(_itemFilter, currValue, false);
190219
}
191220
}
192221

@@ -204,11 +233,11 @@ public void writeEndArray() throws IOException
204233
public void writeStartObject() throws IOException
205234
{
206235
if (_itemFilter == null) {
207-
_filterContext = _filterContext.createChildObjectContext(_itemFilter, false);
236+
_filterContext = _filterContext.createChildObjectContext(_itemFilter, null, false);
208237
return;
209238
}
210239
if (_itemFilter == TokenFilter.INCLUDE_ALL) {
211-
_filterContext = _filterContext.createChildObjectContext(_itemFilter, true);
240+
_filterContext = _filterContext.createChildObjectContext(_itemFilter, null, true);
212241
delegate.writeStartObject();
213242
return;
214243
}
@@ -223,23 +252,53 @@ public void writeStartObject() throws IOException
223252
}
224253
if (f == TokenFilter.INCLUDE_ALL) {
225254
_checkParentPath();
226-
_filterContext = _filterContext.createChildObjectContext(f, true);
255+
_filterContext = _filterContext.createChildObjectContext(f, null, true);
227256
delegate.writeStartObject();
228257
} else { // filter out
229-
_filterContext = _filterContext.createChildObjectContext(f, false);
258+
_filterContext = _filterContext.createChildObjectContext(f, null, false);
230259
}
231260
}
232-
261+
262+
@Override
263+
public void writeStartObject(Object currValue) throws IOException
264+
{
265+
if (_itemFilter == null) {
266+
_filterContext = _filterContext.createChildObjectContext(_itemFilter, currValue, false);
267+
return;
268+
}
269+
if (_itemFilter == TokenFilter.INCLUDE_ALL) {
270+
_filterContext = _filterContext.createChildObjectContext(_itemFilter, currValue, true);
271+
delegate.writeStartObject(currValue);
272+
return;
273+
}
274+
275+
TokenFilter f = _filterContext.checkValue(_itemFilter);
276+
if (f == null) {
277+
return;
278+
}
279+
280+
if (f != TokenFilter.INCLUDE_ALL) {
281+
f = f.filterStartObject();
282+
}
283+
if (f == TokenFilter.INCLUDE_ALL) {
284+
_checkParentPath();
285+
_filterContext = _filterContext.createChildObjectContext(f, currValue, true);
286+
delegate.writeStartObject(currValue);
287+
} else { // filter out
288+
_filterContext = _filterContext.createChildObjectContext(f, currValue, false);
289+
}
290+
}
291+
233292
@Override
234-
public void writeStartObject(Object forValue) throws IOException
293+
public void writeStartObject(Object currValue, int size) throws IOException
235294
{
236295
if (_itemFilter == null) {
237-
_filterContext = _filterContext.createChildObjectContext(_itemFilter, false);
296+
_filterContext = _filterContext.createChildObjectContext(_itemFilter, currValue, false);
238297
return;
239298
}
240299
if (_itemFilter == TokenFilter.INCLUDE_ALL) {
241-
_filterContext = _filterContext.createChildObjectContext(_itemFilter, true);
242-
delegate.writeStartObject(forValue);
300+
_filterContext = _filterContext.createChildObjectContext(_itemFilter, currValue, true);
301+
delegate.writeStartObject(currValue, size);
243302
return;
244303
}
245304

@@ -253,10 +312,10 @@ public void writeStartObject(Object forValue) throws IOException
253312
}
254313
if (f == TokenFilter.INCLUDE_ALL) {
255314
_checkParentPath();
256-
_filterContext = _filterContext.createChildObjectContext(f, true);
257-
delegate.writeStartObject(forValue);
315+
_filterContext = _filterContext.createChildObjectContext(f, currValue, true);
316+
delegate.writeStartObject(currValue, size);
258317
} else { // filter out
259-
_filterContext = _filterContext.createChildObjectContext(f, false);
318+
_filterContext = _filterContext.createChildObjectContext(f, currValue, false);
260319
}
261320
}
262321

0 commit comments

Comments
 (0)