88import com .fasterxml .jackson .core .*;
99import com .fasterxml .jackson .core .base .GeneratorBase ;
1010import com .fasterxml .jackson .core .io .CharacterEscapes ;
11- import com .fasterxml .jackson .core .json .JsonWriteContext ;
1211import com .fasterxml .jackson .core .io .IOContext ;
1312import com .fasterxml .jackson .dataformat .csv .impl .CsvEncoder ;
1413import com .fasterxml .jackson .dataformat .csv .impl .SimpleTokenWriteContext ;
@@ -166,7 +165,7 @@ private Feature(boolean defaultState) {
166165 *
167166 * @since 2.11
168167 */
169- protected SimpleTokenWriteContext _csvWriteContext ;
168+ protected SimpleTokenWriteContext _tokenWriteContext ;
170169
171170 protected CharacterEscapes _characterEscapes = null ;
172171
@@ -244,7 +243,8 @@ public CsvGenerator(IOContext ctxt, int jsonFeatures, int csvFeatures,
244243 _formatFeatures = csvFeatures ;
245244 _schema = schema ;
246245 _writer = new CsvEncoder (ctxt , csvFeatures , out , schema );
247- _csvWriteContext = SimpleTokenWriteContext .createRootContext (null );
246+ _writeContext = null ; // just to make sure it won't be used
247+ _tokenWriteContext = SimpleTokenWriteContext .createRootContext (null );
248248 _writer .setOutputEscapes (CsvCharacterEscapes .fromCsvFeatures (csvFeatures ).getEscapeCodesForAscii ());
249249 }
250250
@@ -255,7 +255,8 @@ public CsvGenerator(IOContext ctxt, int jsonFeatures, int csvFeatures,
255255 _ioContext = ctxt ;
256256 _formatFeatures = csvFeatures ;
257257 _writer = csvWriter ;
258- _csvWriteContext = SimpleTokenWriteContext .createRootContext (null );
258+ _writeContext = null ; // just to make sure it won't be used
259+ _tokenWriteContext = SimpleTokenWriteContext .createRootContext (null );
259260 }
260261
261262 /*
@@ -310,7 +311,7 @@ public int getOutputBuffered() {
310311
311312 @ Override
312313 public SimpleTokenWriteContext getOutputContext () {
313- return _csvWriteContext ;
314+ return _tokenWriteContext ;
314315 }
315316
316317 @ Override
@@ -395,7 +396,7 @@ public boolean canOmitFields() {
395396 @ Override
396397 public final void writeFieldName (String name ) throws IOException
397398 {
398- if (!_csvWriteContext .writeFieldName (name )) {
399+ if (!_tokenWriteContext .writeFieldName (name )) {
399400 _reportError ("Can not write a field name, expecting a value" );
400401 }
401402 _writeFieldName (name );
@@ -405,7 +406,7 @@ public final void writeFieldName(String name) throws IOException
405406 public final void writeFieldName (SerializableString name ) throws IOException
406407 {
407408 // Object is a value, need to verify it's allowed
408- if (!_csvWriteContext .writeFieldName (name .getValue ())) {
409+ if (!_tokenWriteContext .writeFieldName (name .getValue ())) {
409410 _reportError ("Can not write a field name, expecting a value" );
410411 }
411412 _writeFieldName (name .getValue ());
@@ -507,10 +508,10 @@ public final void writeStartArray() throws IOException
507508 _verifyValueWrite ("start an array" );
508509 // Ok to create root-level array to contain Objects/Arrays, but
509510 // can not nest arrays in objects
510- if (_csvWriteContext .inObject ()) {
511+ if (_tokenWriteContext .inObject ()) {
511512 if ((_skipWithin == null )
512513 && _skipValue && isEnabled (JsonGenerator .Feature .IGNORE_UNKNOWN )) {
513- _skipWithin = _csvWriteContext ;
514+ _skipWithin = _tokenWriteContext ;
514515 } else if (!_skipValue ) {
515516 // First: column may have its own separator
516517 String sep ;
@@ -540,20 +541,20 @@ && _skipValue && isEnabled(JsonGenerator.Feature.IGNORE_UNKNOWN)) {
540541 _reportError ("CSV generator does not support nested Array values" );
541542 }
542543 }
543- _csvWriteContext = _csvWriteContext .createChildArrayContext (null );
544+ _tokenWriteContext = _tokenWriteContext .createChildArrayContext (null );
544545 // and that's about it, really
545546 }
546547
547548 @ Override
548549 public final void writeEndArray () throws IOException
549550 {
550- if (!_csvWriteContext .inArray ()) {
551- _reportError ("Current context not Array but " +_csvWriteContext .typeDesc ());
551+ if (!_tokenWriteContext .inArray ()) {
552+ _reportError ("Current context not Array but " +_tokenWriteContext .typeDesc ());
552553 }
553- _csvWriteContext = _csvWriteContext .getParent ();
554+ _tokenWriteContext = _tokenWriteContext .getParent ();
554555 // 14-Dec-2015, tatu: To complete skipping of ignored structured value, need this:
555556 if (_skipWithin != null ) {
556- if (_csvWriteContext == _skipWithin ) {
557+ if (_tokenWriteContext == _skipWithin ) {
557558 _skipWithin = null ;
558559 }
559560 return ;
@@ -564,7 +565,7 @@ public final void writeEndArray() throws IOException
564565 }
565566 // 20-Nov-2014, tatu: When doing "untyped"/"raw" output, this means that row
566567 // is now done. But not if writing such an array field, so:
567- if (!_csvWriteContext .inObject ()) {
568+ if (!_tokenWriteContext .inObject ()) {
568569 finishRow ();
569570 }
570571 }
@@ -575,30 +576,30 @@ public final void writeStartObject() throws IOException
575576 _verifyValueWrite ("start an object" );
576577 // No nesting for objects; can write Objects inside logical root-level arrays.
577578 // 14-Dec-2015, tatu: ... except, should be fine if we are ignoring the property
578- if (_csvWriteContext .inObject () ||
579+ if (_tokenWriteContext .inObject () ||
579580 // 07-Nov-2017, tatu: But we may actually be nested indirectly; so check
580- (_csvWriteContext .inArray () && !_csvWriteContext .getParent ().inRoot ())) {
581+ (_tokenWriteContext .inArray () && !_tokenWriteContext .getParent ().inRoot ())) {
581582 if (_skipWithin == null ) { // new in 2.7
582583 if (_skipValue && isEnabled (JsonGenerator .Feature .IGNORE_UNKNOWN )) {
583- _skipWithin = _csvWriteContext ;
584+ _skipWithin = _tokenWriteContext ;
584585 } else {
585586 _reportMappingError ("CSV generator does not support Object values for properties (nested Objects)" );
586587 }
587588 }
588589 }
589- _csvWriteContext = _csvWriteContext .createChildObjectContext (null );
590+ _tokenWriteContext = _tokenWriteContext .createChildObjectContext (null );
590591 }
591592
592593 @ Override
593594 public final void writeEndObject () throws IOException
594595 {
595- if (!_csvWriteContext .inObject ()) {
596- _reportError ("Current context not Object but " +_csvWriteContext .typeDesc ());
596+ if (!_tokenWriteContext .inObject ()) {
597+ _reportError ("Current context not Object but " +_tokenWriteContext .typeDesc ());
597598 }
598- _csvWriteContext = _csvWriteContext .getParent ();
599+ _tokenWriteContext = _tokenWriteContext .getParent ();
599600 // 14-Dec-2015, tatu: To complete skipping of ignored structured value, need this:
600601 if (_skipWithin != null ) {
601- if (_csvWriteContext == _skipWithin ) {
602+ if (_tokenWriteContext == _skipWithin ) {
602603 _skipWithin = null ;
603604 }
604605 return ;
@@ -775,16 +776,16 @@ public void writeNull() throws IOException
775776 if (!_skipValue ) {
776777 if (!_arraySeparator .isEmpty ()) {
777778 _addToArray (_schema .getNullValueOrEmpty ());
778- } else if (_csvWriteContext .inObject ()) {
779+ } else if (_tokenWriteContext .inObject ()) {
779780 _writer .writeNull (_columnIndex ());
780- } else if (_csvWriteContext .inArray ()) {
781+ } else if (_tokenWriteContext .inArray ()) {
781782 // [dataformat-csv#106]: Need to make sure we don't swallow nulls in arrays either
782783 // 04-Jan-2016, tatu: but check for case of array-wrapping, in which case null stands for absence
783784 // of Object. In this case, could either add an empty row, or skip -- for now, we'll
784785 // just skip; can change, if so desired, to expose "root null" as empty rows, possibly
785786 // based on either schema property, or CsvGenerator.Feature.
786787 // Note: if nulls are to be written that way, would need to call `finishRow()` right after `writeNull()`
787- if (!_csvWriteContext .getParent ().inRoot ()) {
788+ if (!_tokenWriteContext .getParent ().inRoot ()) {
788789 _writer .writeNull (_columnIndex ());
789790 }
790791
@@ -924,7 +925,7 @@ public void writeOmittedField(String fieldName) throws IOException
924925 // assumed to have been removed from schema too
925926 } else {
926927 // basically combination of "writeFieldName()" and "writeNull()"
927- if (!_csvWriteContext .writeFieldName (fieldName )) {
928+ if (!_tokenWriteContext .writeFieldName (fieldName )) {
928929 _reportError ("Can not skip a field, expecting a value" );
929930 }
930931 // and all we do is just note index to use for following value write
@@ -944,7 +945,7 @@ public void writeOmittedField(String fieldName) throws IOException
944945 @ Override
945946 protected final void _verifyValueWrite (String typeMsg ) throws IOException
946947 {
947- if (!_csvWriteContext .writeValue ()) {
948+ if (!_tokenWriteContext .writeValue ()) {
948949 _reportError ("Can not " +typeMsg +", expecting field name" );
949950 }
950951 if (_handleFirstLine ) {
0 commit comments