Skip to content

Commit ed79f76

Browse files
committed
Merge branch '2.10'
2 parents 27f9fb3 + 2ea7b19 commit ed79f76

File tree

5 files changed

+95
-123
lines changed

5 files changed

+95
-123
lines changed

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

Lines changed: 70 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ public abstract class JsonGenerator
2828
implements Closeable, Flushable, Versioned
2929
{
3030
/*
31-
/**********************************************************
31+
/**********************************************************************
3232
/* Construction, initialization
33-
/**********************************************************
33+
/**********************************************************************
3434
*/
3535

3636
protected JsonGenerator() { }
3737

3838
/*
39-
/**********************************************************
39+
/**********************************************************************
4040
/* Versioned
41-
/**********************************************************
41+
/**********************************************************************
4242
*/
4343

4444
/**
@@ -48,9 +48,9 @@ protected JsonGenerator() { }
4848
public abstract Version version();
4949

5050
/*
51-
/**********************************************************
51+
/**********************************************************************
5252
/* Public API, output configuration, state access
53-
/**********************************************************
53+
/**********************************************************************
5454
*/
5555

5656
/**
@@ -130,9 +130,9 @@ public int getOutputBuffered() {
130130
public abstract void setCurrentValue(Object v);
131131

132132
/*
133-
/**********************************************************
133+
/**********************************************************************
134134
/* Public API, Feature configuration
135-
/**********************************************************
135+
/**********************************************************************
136136
*/
137137

138138
/**
@@ -189,9 +189,9 @@ public final JsonGenerator configure(StreamWriteFeature f, boolean state) {
189189
public abstract int formatWriteFeatures();
190190

191191
/*
192-
/**********************************************************
192+
/**********************************************************************
193193
/* Public API, Schema configuration
194-
/**********************************************************
194+
/**********************************************************************
195195
*/
196196

197197
/**
@@ -281,9 +281,9 @@ public void setSchema(FormatSchema schema) {
281281
public JsonGenerator setCharacterEscapes(CharacterEscapes esc) { return this; }
282282

283283
/*
284-
/**********************************************************
284+
/**********************************************************************
285285
/* Public API, capability introspection methods
286-
/**********************************************************
286+
/**********************************************************************
287287
*/
288288

289289
/**
@@ -355,9 +355,9 @@ public void setSchema(FormatSchema schema) {
355355
public boolean canWriteFormattedNumbers() { return false; }
356356

357357
/*
358-
/**********************************************************
358+
/**********************************************************************
359359
/* Public API, write methods, structural
360-
/**********************************************************
360+
/**********************************************************************
361361
*/
362362

363363
/**
@@ -414,7 +414,7 @@ public void writeStartArray(int size) throws IOException {
414414
public abstract void writeEndArray() throws IOException;
415415

416416
/**
417-
* Method for writing starting marker of a JSON Object value
417+
* Method for writing starting marker of an Object value
418418
* (character '{'; plus possible white space decoration
419419
* if pretty-printing is enabled).
420420
*<p>
@@ -425,10 +425,9 @@ public void writeStartArray(int size) throws IOException {
425425
public abstract void writeStartObject() throws IOException;
426426

427427
/**
428-
* Method for writing starting marker of a JSON Object value
429-
* (character '{'; plus possible white space decoration
430-
* if pretty-printing is enabled), to represent Java given
431-
* as the argument. Argument is offered as metadata, but more
428+
* Method for writing starting marker of an Object value
429+
* to represent the given Java Object value.
430+
* Argument is offered as metadata, but more
432431
* importantly it should be assigned as the "current value"
433432
* for the Object content that gets constructed and initialized.
434433
*<p>
@@ -439,7 +438,27 @@ public void writeStartArray(int size) throws IOException {
439438
public abstract void writeStartObject(Object forValue) throws IOException;
440439

441440
/**
442-
* Method for writing closing marker of a JSON Object value
441+
* Method for writing starting marker of an Object value
442+
* to represent the given Java Object value.
443+
* Argument is offered as metadata, but more
444+
* importantly it should be assigned as the "current value"
445+
* for the Object content that gets constructed and initialized.
446+
* In addition, caller knows number of key/value pairs ("properties")
447+
* that will get written for the Object value: this is relevant for
448+
* some format backends (but not, as an example, for JSON).
449+
*<p>
450+
* Object values can be written in any context where values
451+
* are allowed: meaning everywhere except for when
452+
* a field name is expected.
453+
*/
454+
public void writeStartObject(Object forValue, int size) throws IOException
455+
{
456+
writeStartObject();
457+
setCurrentValue(forValue);
458+
}
459+
460+
/**
461+
* Method for writing closing marker of an Object value
443462
* (character '}'; plus possible white space decoration
444463
* if pretty-printing is enabled).
445464
*<p>
@@ -487,9 +506,9 @@ public void writeFieldId(long id) throws IOException {
487506
}
488507

489508
/*
490-
/**********************************************************
491-
/* Public API, write methods, scalar arrays (2.8)
492-
/**********************************************************
509+
/**********************************************************************
510+
/* Public API, write methods, scalar arrays
511+
/**********************************************************************
493512
*/
494513

495514
/**
@@ -507,7 +526,7 @@ public void writeArray(int[] array, int offset, int length) throws IOException
507526
throw new IllegalArgumentException("null array");
508527
}
509528
_verifyOffsets(array.length, offset, length);
510-
writeStartArray();
529+
writeStartArray(array, length);
511530
for (int i = offset, end = offset+length; i < end; ++i) {
512531
writeNumber(array[i]);
513532
}
@@ -529,7 +548,7 @@ public void writeArray(long[] array, int offset, int length) throws IOException
529548
throw new IllegalArgumentException("null array");
530549
}
531550
_verifyOffsets(array.length, offset, length);
532-
writeStartArray();
551+
writeStartArray(array, length);
533552
for (int i = offset, end = offset+length; i < end; ++i) {
534553
writeNumber(array[i]);
535554
}
@@ -551,17 +570,17 @@ public void writeArray(double[] array, int offset, int length) throws IOExceptio
551570
throw new IllegalArgumentException("null array");
552571
}
553572
_verifyOffsets(array.length, offset, length);
554-
writeStartArray();
573+
writeStartArray(array, length);
555574
for (int i = offset, end = offset+length; i < end; ++i) {
556575
writeNumber(array[i]);
557576
}
558577
writeEndArray();
559578
}
560579

561580
/*
562-
/**********************************************************
581+
/**********************************************************************
563582
/* Public API, write methods, text/String values
564-
/**********************************************************
583+
/**********************************************************************
565584
*/
566585

567586
/**
@@ -648,9 +667,9 @@ public abstract void writeUTF8String(byte[] text, int offset, int length)
648667
throws IOException;
649668

650669
/*
651-
/**********************************************************
670+
/**********************************************************************
652671
/* Public API, write methods, binary/raw content
653-
/**********************************************************
672+
/**********************************************************************
654673
*/
655674

656675
/**
@@ -838,9 +857,9 @@ public abstract int writeBinary(Base64Variant bv,
838857
InputStream data, int dataLength) throws IOException;
839858

840859
/*
841-
/**********************************************************
860+
/**********************************************************************
842861
/* Public API, write methods, numeric
843-
/**********************************************************
862+
/**********************************************************************
844863
*/
845864

846865
/**
@@ -944,9 +963,9 @@ public abstract int writeBinary(Base64Variant bv,
944963
public abstract void writeNumber(String encodedValue) throws IOException;
945964

946965
/*
947-
/**********************************************************
966+
/**********************************************************************
948967
/* Public API, write methods, other value types
949-
/**********************************************************
968+
/**********************************************************************
950969
*/
951970

952971
/**
@@ -986,11 +1005,11 @@ public void writeEmbeddedObject(Object object) throws IOException {
9861005
+object.getClass().getName(),
9871006
this);
9881007
}
989-
1008+
9901009
/*
991-
/**********************************************************
1010+
/**********************************************************************
9921011
/* Public API, write methods, Native Ids (type, object)
993-
/**********************************************************
1012+
/**********************************************************************
9941013
*/
9951014

9961015
/**
@@ -1140,9 +1159,9 @@ public WritableTypeId writeTypeSuffix(WritableTypeId typeIdDef) throws IOExcepti
11401159
}
11411160

11421161
/*
1143-
/**********************************************************
1162+
/**********************************************************************
11441163
/* Public API, write methods, serializing Java objects
1145-
/**********************************************************
1164+
/**********************************************************************
11461165
*/
11471166

11481167
/**
@@ -1162,9 +1181,9 @@ public WritableTypeId writeTypeSuffix(WritableTypeId typeIdDef) throws IOExcepti
11621181
public abstract void writeTree(TreeNode rootNode) throws IOException;
11631182

11641183
/*
1165-
/**********************************************************
1184+
/**********************************************************************
11661185
/* Public API, convenience field write methods
1167-
/**********************************************************
1186+
/**********************************************************************
11681187
*/
11691188

11701189
/**
@@ -1308,7 +1327,7 @@ public final void writeArrayFieldStart(String fieldName) throws IOException {
13081327

13091328
/**
13101329
* Convenience method for outputting a field entry ("member")
1311-
* (that will contain a JSON Object value), and the START_OBJECT marker.
1330+
* (that will contain an Object value), and the START_OBJECT marker.
13121331
* Equivalent to:
13131332
*<pre>
13141333
* writeFieldName(fieldName);
@@ -1346,11 +1365,11 @@ public final void writeObjectField(String fieldName, Object pojo) throws IOExcep
13461365
* Default implementation does nothing.
13471366
*/
13481367
public void writeOmittedField(String fieldName) throws IOException { }
1349-
1368+
13501369
/*
1351-
/**********************************************************
1370+
/**********************************************************************
13521371
/* Public API, copy-through methods
1353-
/**********************************************************
1372+
/**********************************************************************
13541373
*/
13551374

13561375
/**
@@ -1502,9 +1521,9 @@ public void copyCurrentStructure(JsonParser p) throws IOException
15021521
}
15031522

15041523
/*
1505-
/**********************************************************
1524+
/**********************************************************************
15061525
/* Public API, buffer handling
1507-
/**********************************************************
1526+
/**********************************************************************
15081527
*/
15091528

15101529
/**
@@ -1522,9 +1541,9 @@ public void copyCurrentStructure(JsonParser p) throws IOException
15221541
public abstract boolean isClosed();
15231542

15241543
/*
1525-
/**********************************************************
1544+
/**********************************************************************
15261545
/* Closeable implementation
1527-
/**********************************************************
1546+
/**********************************************************************
15281547
*/
15291548

15301549
/**
@@ -1543,9 +1562,9 @@ public void copyCurrentStructure(JsonParser p) throws IOException
15431562
public abstract void close() throws IOException;
15441563

15451564
/*
1546-
/**********************************************************
1565+
/**********************************************************************
15471566
/* Helper methods for sub-classes
1548-
/**********************************************************
1567+
/**********************************************************************
15491568
*/
15501569

15511570
/**

0 commit comments

Comments
 (0)