@@ -201,6 +201,14 @@ private Feature(boolean defaultState) {
201
201
*/
202
202
protected int _nextColumnByName = -1 ;
203
203
204
+ /**
205
+ * Decorator to use for decorating the column value to follow, if any;
206
+ * {@code null} if none.
207
+ *
208
+ * @since 2.18
209
+ */
210
+ protected CsvValueDecorator _nextColumnDecorator ;
211
+
204
212
/**
205
213
* Flag set when property to write is unknown, and the matching value
206
214
* is to be skipped quietly.
@@ -396,14 +404,16 @@ private final void _writeFieldName(String name) throws JacksonException
396
404
if (_skipWithin != null ) { // new in 2.7
397
405
_skipValue = true ;
398
406
_nextColumnByName = -1 ;
407
+ _nextColumnDecorator = null ;
399
408
return ;
400
409
}
401
410
// note: we are likely to get next column name, so pass it as hint
402
411
CsvSchema .Column col = _schema .column (name , _nextColumnByName +1 );
403
412
if (col == null ) {
413
+ _nextColumnByName = -1 ;
414
+ _nextColumnDecorator = null ;
404
415
if (isEnabled (StreamWriteFeature .IGNORE_UNKNOWN )) {
405
416
_skipValue = true ;
406
- _nextColumnByName = -1 ;
407
417
return ;
408
418
}
409
419
// not a low-level error, so:
@@ -412,6 +422,7 @@ private final void _writeFieldName(String name) throws JacksonException
412
422
_skipValue = false ;
413
423
// and all we do is just note index to use for following value write
414
424
_nextColumnByName = col .getIndex ();
425
+ _nextColumnDecorator = col .getValueDecorator ();
415
426
}
416
427
417
428
/*
@@ -534,8 +545,13 @@ public JsonGenerator writeEndArray() throws JacksonException
534
545
return this ;
535
546
}
536
547
if (!_arraySeparator .isEmpty ()) {
548
+ String value = _arrayContents .toString ();
549
+ // 26-Aug-2024, tatu: [dataformats-text#495] Decorations!
550
+ if (_nextColumnDecorator != null ) {
551
+ value = _nextColumnDecorator .decorateValue (this , value );
552
+ }
537
553
_arraySeparator = CsvSchema .NO_ARRAY_ELEMENT_SEPARATOR ;
538
- _writer .write (_columnIndex (), _arrayContents . toString () );
554
+ _writer .write (_columnIndex (), value );
539
555
}
540
556
// 20-Nov-2014, tatu: When doing "untyped"/"raw" output, this means that row
541
557
// is now done. But not if writing such an array property, so:
@@ -610,6 +626,10 @@ public JsonGenerator writeString(String text) throws JacksonException
610
626
if (!_arraySeparator .isEmpty ()) {
611
627
_addToArray (text );
612
628
} else {
629
+ // 26-Aug-2024, tatu: [dataformats-text#495] Decorations!
630
+ if (_nextColumnDecorator != null ) {
631
+ text = _nextColumnDecorator .decorateValue (this , text );
632
+ }
613
633
_writer .write (_columnIndex (), text );
614
634
}
615
635
}
@@ -623,6 +643,11 @@ public JsonGenerator writeString(char[] text, int offset, int len) throws Jackso
623
643
if (!_skipValue ) {
624
644
if (!_arraySeparator .isEmpty ()) {
625
645
_addToArray (new String (text , offset , len ));
646
+ // 26-Aug-2024, tatu: [dataformats-text#495] Decorations!
647
+ } else if (_nextColumnDecorator != null ) {
648
+ String str = new String (text , offset , len );
649
+ _writer .write (_columnIndex (),
650
+ _nextColumnDecorator .decorateValue (this , str ));
626
651
} else {
627
652
_writer .write (_columnIndex (), text , offset , len );
628
653
}
@@ -638,7 +663,12 @@ public JsonGenerator writeString(SerializableString sstr) throws JacksonExceptio
638
663
if (!_arraySeparator .isEmpty ()) {
639
664
_addToArray (sstr .getValue ());
640
665
} else {
641
- _writer .write (_columnIndex (), sstr .getValue ());
666
+ // 26-Aug-2024, tatu: [dataformats-text#495] Decorations!
667
+ String text = sstr .getValue ();
668
+ if (_nextColumnDecorator != null ) {
669
+ text = _nextColumnDecorator .decorateValue (this , text );
670
+ }
671
+ _writer .write (_columnIndex (), text );
642
672
}
643
673
}
644
674
return this ;
@@ -727,6 +757,7 @@ public JsonGenerator writeBinary(Base64Variant b64variant, byte[] data, int offs
727
757
if (data == null ) {
728
758
return writeNull ();
729
759
}
760
+
730
761
_verifyValueWrite ("write Binary value" );
731
762
if (!_skipValue ) {
732
763
// ok, better just Base64 encode as a String...
@@ -738,6 +769,10 @@ public JsonGenerator writeBinary(Base64Variant b64variant, byte[] data, int offs
738
769
if (!_arraySeparator .isEmpty ()) {
739
770
_addToArray (encoded );
740
771
} else {
772
+ // 26-Aug-2024, tatu: [dataformats-text#495] Decorations!
773
+ if (_nextColumnDecorator != null ) {
774
+ encoded = _nextColumnDecorator .decorateValue (this , encoded );
775
+ }
741
776
_writer .write (_columnIndex (), encoded );
742
777
}
743
778
}
@@ -758,7 +793,13 @@ public JsonGenerator writeBoolean(boolean state) throws JacksonException
758
793
if (!_arraySeparator .isEmpty ()) {
759
794
_addToArray (state ? "true" : "false" );
760
795
} else {
761
- _writer .write (_columnIndex (), state );
796
+ // 26-Aug-2024, tatu: [dataformats-text#495] Decorations!
797
+ if (_nextColumnDecorator != null ) {
798
+ String text = _nextColumnDecorator .decorateValue (this , state ? "true" : "false" );
799
+ _writer .write (_columnIndex (), text );
800
+ } else {
801
+ _writer .write (_columnIndex (), state );
802
+ }
762
803
}
763
804
}
764
805
return this ;
@@ -773,6 +814,15 @@ public JsonGenerator writeNull() throws JacksonException
773
814
if (!_arraySeparator .isEmpty ()) {
774
815
_addToArray (_schema .getNullValueOrEmpty ());
775
816
} else if (_streamWriteContext .inObject ()) {
817
+ // 26-Aug-2024, tatu: [dataformats-text#495] Decorations?
818
+ if (_nextColumnDecorator != null ) {
819
+ String nvl = _nextColumnDecorator .decorateNull (this );
820
+ if (nvl != null ) {
821
+ _writer .write (_columnIndex (), nvl );
822
+ return this ;
823
+ }
824
+ }
825
+
776
826
_writer .writeNull (_columnIndex ());
777
827
} else if (_streamWriteContext .inArray ()) {
778
828
// [dataformat-csv#106]: Need to make sure we don't swallow nulls in arrays either
@@ -782,6 +832,14 @@ public JsonGenerator writeNull() throws JacksonException
782
832
// based on either schema property, or CsvGenerator.Feature.
783
833
// Note: if nulls are to be written that way, would need to call `finishRow()` right after `writeNull()`
784
834
if (!_streamWriteContext .getParent ().inRoot ()) {
835
+ // 26-Aug-2024, tatu: [dataformats-text#495] Decorations?
836
+ if (_nextColumnDecorator != null ) {
837
+ String nvl = _nextColumnDecorator .decorateNull (this );
838
+ if (nvl != null ) {
839
+ _writer .write (_columnIndex (), nvl );
840
+ return this ;
841
+ }
842
+ }
785
843
_writer .writeNull (_columnIndex ());
786
844
}
787
845
@@ -807,6 +865,10 @@ public JsonGenerator writeNumber(int v) throws JacksonException
807
865
if (!_skipValue ) {
808
866
if (!_arraySeparator .isEmpty ()) {
809
867
_addToArray (String .valueOf (v ));
868
+ // 26-Aug-2024, tatu: [dataformats-text#495] Decorations?
869
+ } else if (_nextColumnDecorator != null ) {
870
+ _writer .write (_columnIndex (),
871
+ _nextColumnDecorator .decorateValue (this , String .valueOf (v )));
810
872
} else {
811
873
_writer .write (_columnIndex (), v );
812
874
}
@@ -825,6 +887,10 @@ public JsonGenerator writeNumber(long v) throws JacksonException
825
887
if (!_skipValue ) {
826
888
if (!_arraySeparator .isEmpty ()) {
827
889
_addToArray (String .valueOf (v ));
890
+ // 26-Aug-2024, tatu: [dataformats-text#495] Decorations?
891
+ } else if (_nextColumnDecorator != null ) {
892
+ _writer .write (_columnIndex (),
893
+ _nextColumnDecorator .decorateValue (this , String .valueOf (v )));
828
894
} else {
829
895
_writer .write (_columnIndex (), v );
830
896
}
@@ -842,6 +908,10 @@ public JsonGenerator writeNumber(BigInteger v) throws JacksonException
842
908
if (!_skipValue ) {
843
909
if (!_arraySeparator .isEmpty ()) {
844
910
_addToArray (String .valueOf (v ));
911
+ // 26-Aug-2024, tatu: [dataformats-text#495] Decorations?
912
+ } else if (_nextColumnDecorator != null ) {
913
+ _writer .write (_columnIndex (),
914
+ _nextColumnDecorator .decorateValue (this , String .valueOf (v )));
845
915
} else {
846
916
_writer .write (_columnIndex (), v );
847
917
@@ -857,6 +927,10 @@ public JsonGenerator writeNumber(double v) throws JacksonException
857
927
if (!_skipValue ) {
858
928
if (!_arraySeparator .isEmpty ()) {
859
929
_addToArray (String .valueOf (v ));
930
+ // 26-Aug-2024, tatu: [dataformats-text#495] Decorations?
931
+ } else if (_nextColumnDecorator != null ) {
932
+ _writer .write (_columnIndex (),
933
+ _nextColumnDecorator .decorateValue (this , String .valueOf (v )));
860
934
} else {
861
935
_writer .write (_columnIndex (), v );
862
936
}
@@ -871,6 +945,10 @@ public JsonGenerator writeNumber(float v) throws JacksonException
871
945
if (!_skipValue ) {
872
946
if (!_arraySeparator .isEmpty ()) {
873
947
_addToArray (String .valueOf (v ));
948
+ // 26-Aug-2024, tatu: [dataformats-text#495] Decorations?
949
+ } else if (_nextColumnDecorator != null ) {
950
+ _writer .write (_columnIndex (),
951
+ _nextColumnDecorator .decorateValue (this , String .valueOf (v )));
874
952
} else {
875
953
_writer .write (_columnIndex (), v );
876
954
}
@@ -889,6 +967,11 @@ public JsonGenerator writeNumber(BigDecimal v) throws JacksonException
889
967
boolean plain = isEnabled (StreamWriteFeature .WRITE_BIGDECIMAL_AS_PLAIN );
890
968
if (!_arraySeparator .isEmpty ()) {
891
969
_addToArray (plain ? v .toPlainString () : v .toString ());
970
+ // 26-Aug-2024, tatu: [dataformats-text#495] Decorations?
971
+ } else if (_nextColumnDecorator != null ) {
972
+ String numStr = plain ? v .toPlainString () : v .toString ();
973
+ _writer .write (_columnIndex (),
974
+ _nextColumnDecorator .decorateValue (this , numStr ));
892
975
} else {
893
976
_writer .write (_columnIndex (), v , plain );
894
977
}
@@ -906,6 +989,10 @@ public JsonGenerator writeNumber(String encodedValue) throws JacksonException
906
989
if (!_skipValue ) {
907
990
if (!_arraySeparator .isEmpty ()) {
908
991
_addToArray (encodedValue );
992
+ // 26-Aug-2024, tatu: [dataformats-text#495] Decorations?
993
+ } else if (_nextColumnDecorator != null ) {
994
+ _writer .write (_columnIndex (),
995
+ _nextColumnDecorator .decorateValue (this , encodedValue ));
909
996
} else {
910
997
_writer .write (_columnIndex (), encodedValue );
911
998
}
0 commit comments