@@ -153,7 +153,7 @@ private Feature(boolean defaultState) {
153
153
*/
154
154
protected boolean _closed ;
155
155
156
- final protected IOContext _ioContext ;
156
+ protected final IOContext _ioContext ;
157
157
158
158
/*
159
159
/**********************************************************
@@ -179,6 +179,16 @@ private Feature(boolean defaultState) {
179
179
180
180
protected String _currText ;
181
181
182
+ /**
183
+ * Additional flag that is strictly needed when exposing "mixed" leading
184
+ * String value as "anonymous" property/string pair. If so, code returns
185
+ * START_OBJECT first, sets {@code _nextToken} to be {@code FIELD_NAME}
186
+ * and sets this flag to indicate use of "anonymous" marker.
187
+ *
188
+ * @since 2.13
189
+ */
190
+ protected boolean _nextIsLeadingMixed ;
191
+
182
192
/*
183
193
/**********************************************************
184
194
/* Parsing state, parsed values
@@ -668,7 +678,15 @@ public JsonToken nextToken() throws IOException
668
678
_parsingContext = _parsingContext .getParent ();
669
679
break ;
670
680
case FIELD_NAME :
671
- _parsingContext .setCurrentName (_xmlTokens .getLocalName ());
681
+ // 29-Mar-2021, tatu: [dataformat-xml#442]: special case of leading
682
+ // mixed text added
683
+ if (_nextIsLeadingMixed ) {
684
+ _nextIsLeadingMixed = false ;
685
+ _parsingContext .setCurrentName (_cfgNameForTextElement );
686
+ _nextToken = JsonToken .VALUE_STRING ;
687
+ } else {
688
+ _parsingContext .setCurrentName (_xmlTokens .getLocalName ());
689
+ }
672
690
break ;
673
691
default : // VALUE_STRING, VALUE_NULL
674
692
// 13-May-2020, tatu: [dataformat-xml#397]: advance `index` anyway; not
@@ -756,7 +774,7 @@ public JsonToken nextToken() throws IOException
756
774
_currText = _xmlTokens .getText ();
757
775
if (_mayBeLeaf ) {
758
776
_mayBeLeaf = false ;
759
- // One more refinement (pronunced like "hack") is that if
777
+ // One more refinement (pronounced like "hack") is that if
760
778
// we had an empty String (or all white space), and we are
761
779
// deserializing an array, we better hide the empty text.
762
780
// Also: must skip following END_ELEMENT
@@ -792,7 +810,14 @@ public JsonToken nextToken() throws IOException
792
810
// but... [dataformat-xml#191]: looks like we can't short-cut, must
793
811
// loop over again
794
812
if (_parsingContext .inObject ()) {
795
- if ((_currToken != JsonToken .FIELD_NAME ) && XmlTokenStream ._allWs (_currText )) {
813
+ if (_currToken == JsonToken .FIELD_NAME ) {
814
+ // 29-Mar-2021, tatu: [dataformat-xml#442]: need special handling for
815
+ // leading mixed content; requires 3-token sequence for which _nextToken
816
+ // along is not enough.
817
+ _nextIsLeadingMixed = true ;
818
+ _nextToken = JsonToken .FIELD_NAME ;
819
+ return (_currToken = JsonToken .START_OBJECT );
820
+ } else if (XmlTokenStream ._allWs (_currText )) {
796
821
token = _nextToken ();
797
822
continue ;
798
823
}
@@ -802,6 +827,11 @@ public JsonToken nextToken() throws IOException
802
827
token = _nextToken ();
803
828
continue ;
804
829
}
830
+ // 29-Mar-2021, tatu: This seems like an error condition...
831
+ // How should we indicate it? As of 2.13, report as unexpected state
832
+ throw _constructError (
833
+ "Unexpected non-whitespace text ('" +_currText +"' in Array context: should not occur (or should be handled)"
834
+ );
805
835
}
806
836
807
837
// If not a leaf (or otherwise ignorable), need to transform into property...
0 commit comments