@@ -28,17 +28,17 @@ public abstract class JsonGenerator
28
28
implements Closeable , Flushable , Versioned
29
29
{
30
30
/*
31
- /**********************************************************
31
+ /**********************************************************************
32
32
/* Construction, initialization
33
- /**********************************************************
33
+ /**********************************************************************
34
34
*/
35
35
36
36
protected JsonGenerator () { }
37
37
38
38
/*
39
- /**********************************************************
39
+ /**********************************************************************
40
40
/* Versioned
41
- /**********************************************************
41
+ /**********************************************************************
42
42
*/
43
43
44
44
/**
@@ -48,9 +48,9 @@ protected JsonGenerator() { }
48
48
public abstract Version version ();
49
49
50
50
/*
51
- /**********************************************************
51
+ /**********************************************************************
52
52
/* Public API, output configuration, state access
53
- /**********************************************************
53
+ /**********************************************************************
54
54
*/
55
55
56
56
/**
@@ -130,9 +130,9 @@ public int getOutputBuffered() {
130
130
public abstract void setCurrentValue (Object v );
131
131
132
132
/*
133
- /**********************************************************
133
+ /**********************************************************************
134
134
/* Public API, Feature configuration
135
- /**********************************************************
135
+ /**********************************************************************
136
136
*/
137
137
138
138
/**
@@ -189,9 +189,9 @@ public final JsonGenerator configure(StreamWriteFeature f, boolean state) {
189
189
public abstract int formatWriteFeatures ();
190
190
191
191
/*
192
- /**********************************************************
192
+ /**********************************************************************
193
193
/* Public API, Schema configuration
194
- /**********************************************************
194
+ /**********************************************************************
195
195
*/
196
196
197
197
/**
@@ -281,9 +281,9 @@ public void setSchema(FormatSchema schema) {
281
281
public JsonGenerator setCharacterEscapes (CharacterEscapes esc ) { return this ; }
282
282
283
283
/*
284
- /**********************************************************
284
+ /**********************************************************************
285
285
/* Public API, capability introspection methods
286
- /**********************************************************
286
+ /**********************************************************************
287
287
*/
288
288
289
289
/**
@@ -355,9 +355,9 @@ public void setSchema(FormatSchema schema) {
355
355
public boolean canWriteFormattedNumbers () { return false ; }
356
356
357
357
/*
358
- /**********************************************************
358
+ /**********************************************************************
359
359
/* Public API, write methods, structural
360
- /**********************************************************
360
+ /**********************************************************************
361
361
*/
362
362
363
363
/**
@@ -414,7 +414,7 @@ public void writeStartArray(int size) throws IOException {
414
414
public abstract void writeEndArray () throws IOException ;
415
415
416
416
/**
417
- * Method for writing starting marker of a JSON Object value
417
+ * Method for writing starting marker of an Object value
418
418
* (character '{'; plus possible white space decoration
419
419
* if pretty-printing is enabled).
420
420
*<p>
@@ -425,10 +425,9 @@ public void writeStartArray(int size) throws IOException {
425
425
public abstract void writeStartObject () throws IOException ;
426
426
427
427
/**
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
432
431
* importantly it should be assigned as the "current value"
433
432
* for the Object content that gets constructed and initialized.
434
433
*<p>
@@ -439,7 +438,27 @@ public void writeStartArray(int size) throws IOException {
439
438
public abstract void writeStartObject (Object forValue ) throws IOException ;
440
439
441
440
/**
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
443
462
* (character '}'; plus possible white space decoration
444
463
* if pretty-printing is enabled).
445
464
*<p>
@@ -487,9 +506,9 @@ public void writeFieldId(long id) throws IOException {
487
506
}
488
507
489
508
/*
490
- /**********************************************************
491
- /* Public API, write methods, scalar arrays (2.8)
492
- /**********************************************************
509
+ /**********************************************************************
510
+ /* Public API, write methods, scalar arrays
511
+ /**********************************************************************
493
512
*/
494
513
495
514
/**
@@ -507,7 +526,7 @@ public void writeArray(int[] array, int offset, int length) throws IOException
507
526
throw new IllegalArgumentException ("null array" );
508
527
}
509
528
_verifyOffsets (array .length , offset , length );
510
- writeStartArray ();
529
+ writeStartArray (array , length );
511
530
for (int i = offset , end = offset +length ; i < end ; ++i ) {
512
531
writeNumber (array [i ]);
513
532
}
@@ -529,7 +548,7 @@ public void writeArray(long[] array, int offset, int length) throws IOException
529
548
throw new IllegalArgumentException ("null array" );
530
549
}
531
550
_verifyOffsets (array .length , offset , length );
532
- writeStartArray ();
551
+ writeStartArray (array , length );
533
552
for (int i = offset , end = offset +length ; i < end ; ++i ) {
534
553
writeNumber (array [i ]);
535
554
}
@@ -551,17 +570,17 @@ public void writeArray(double[] array, int offset, int length) throws IOExceptio
551
570
throw new IllegalArgumentException ("null array" );
552
571
}
553
572
_verifyOffsets (array .length , offset , length );
554
- writeStartArray ();
573
+ writeStartArray (array , length );
555
574
for (int i = offset , end = offset +length ; i < end ; ++i ) {
556
575
writeNumber (array [i ]);
557
576
}
558
577
writeEndArray ();
559
578
}
560
579
561
580
/*
562
- /**********************************************************
581
+ /**********************************************************************
563
582
/* Public API, write methods, text/String values
564
- /**********************************************************
583
+ /**********************************************************************
565
584
*/
566
585
567
586
/**
@@ -648,9 +667,9 @@ public abstract void writeUTF8String(byte[] text, int offset, int length)
648
667
throws IOException ;
649
668
650
669
/*
651
- /**********************************************************
670
+ /**********************************************************************
652
671
/* Public API, write methods, binary/raw content
653
- /**********************************************************
672
+ /**********************************************************************
654
673
*/
655
674
656
675
/**
@@ -838,9 +857,9 @@ public abstract int writeBinary(Base64Variant bv,
838
857
InputStream data , int dataLength ) throws IOException ;
839
858
840
859
/*
841
- /**********************************************************
860
+ /**********************************************************************
842
861
/* Public API, write methods, numeric
843
- /**********************************************************
862
+ /**********************************************************************
844
863
*/
845
864
846
865
/**
@@ -944,9 +963,9 @@ public abstract int writeBinary(Base64Variant bv,
944
963
public abstract void writeNumber (String encodedValue ) throws IOException ;
945
964
946
965
/*
947
- /**********************************************************
966
+ /**********************************************************************
948
967
/* Public API, write methods, other value types
949
- /**********************************************************
968
+ /**********************************************************************
950
969
*/
951
970
952
971
/**
@@ -986,11 +1005,11 @@ public void writeEmbeddedObject(Object object) throws IOException {
986
1005
+object .getClass ().getName (),
987
1006
this );
988
1007
}
989
-
1008
+
990
1009
/*
991
- /**********************************************************
1010
+ /**********************************************************************
992
1011
/* Public API, write methods, Native Ids (type, object)
993
- /**********************************************************
1012
+ /**********************************************************************
994
1013
*/
995
1014
996
1015
/**
@@ -1140,9 +1159,9 @@ public WritableTypeId writeTypeSuffix(WritableTypeId typeIdDef) throws IOExcepti
1140
1159
}
1141
1160
1142
1161
/*
1143
- /**********************************************************
1162
+ /**********************************************************************
1144
1163
/* Public API, write methods, serializing Java objects
1145
- /**********************************************************
1164
+ /**********************************************************************
1146
1165
*/
1147
1166
1148
1167
/**
@@ -1162,9 +1181,9 @@ public WritableTypeId writeTypeSuffix(WritableTypeId typeIdDef) throws IOExcepti
1162
1181
public abstract void writeTree (TreeNode rootNode ) throws IOException ;
1163
1182
1164
1183
/*
1165
- /**********************************************************
1184
+ /**********************************************************************
1166
1185
/* Public API, convenience field write methods
1167
- /**********************************************************
1186
+ /**********************************************************************
1168
1187
*/
1169
1188
1170
1189
/**
@@ -1308,7 +1327,7 @@ public final void writeArrayFieldStart(String fieldName) throws IOException {
1308
1327
1309
1328
/**
1310
1329
* 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.
1312
1331
* Equivalent to:
1313
1332
*<pre>
1314
1333
* writeFieldName(fieldName);
@@ -1346,11 +1365,11 @@ public final void writeObjectField(String fieldName, Object pojo) throws IOExcep
1346
1365
* Default implementation does nothing.
1347
1366
*/
1348
1367
public void writeOmittedField (String fieldName ) throws IOException { }
1349
-
1368
+
1350
1369
/*
1351
- /**********************************************************
1370
+ /**********************************************************************
1352
1371
/* Public API, copy-through methods
1353
- /**********************************************************
1372
+ /**********************************************************************
1354
1373
*/
1355
1374
1356
1375
/**
@@ -1502,9 +1521,9 @@ public void copyCurrentStructure(JsonParser p) throws IOException
1502
1521
}
1503
1522
1504
1523
/*
1505
- /**********************************************************
1524
+ /**********************************************************************
1506
1525
/* Public API, buffer handling
1507
- /**********************************************************
1526
+ /**********************************************************************
1508
1527
*/
1509
1528
1510
1529
/**
@@ -1522,9 +1541,9 @@ public void copyCurrentStructure(JsonParser p) throws IOException
1522
1541
public abstract boolean isClosed ();
1523
1542
1524
1543
/*
1525
- /**********************************************************
1544
+ /**********************************************************************
1526
1545
/* Closeable implementation
1527
- /**********************************************************
1546
+ /**********************************************************************
1528
1547
*/
1529
1548
1530
1549
/**
@@ -1543,9 +1562,9 @@ public void copyCurrentStructure(JsonParser p) throws IOException
1543
1562
public abstract void close () throws IOException ;
1544
1563
1545
1564
/*
1546
- /**********************************************************
1565
+ /**********************************************************************
1547
1566
/* Helper methods for sub-classes
1548
- /**********************************************************
1567
+ /**********************************************************************
1549
1568
*/
1550
1569
1551
1570
/**
0 commit comments