@@ -425,7 +425,7 @@ public boolean isExpectedStartArrayToken()
425
425
}
426
426
427
427
// DEBUGGING
428
- /*
428
+ /*
429
429
@Override
430
430
public JsonToken nextToken() throws IOException
431
431
{
@@ -444,8 +444,11 @@ public JsonToken nextToken() throws IOException
444
444
}
445
445
return t;
446
446
}
447
- */
448
447
448
+ // public JsonToken nextToken0() throws IOException
449
+ */
450
+
451
+
449
452
@ Override
450
453
public JsonToken nextToken () throws IOException
451
454
{
@@ -509,81 +512,79 @@ public JsonToken nextToken() throws IOException
509
512
}
510
513
511
514
// Ok; beyond start element, what do we get?
512
- switch (token ) {
513
- case XmlTokenStream .XML_END_ELEMENT :
514
- // Simple, except that if this is a leaf, need to suppress end:
515
- if (_mayBeLeaf ) {
516
- _mayBeLeaf = false ;
517
- if (_parsingContext .inArray ()) {
518
- // 06-Jan-2015, tatu: as per [dataformat-xml#180], need to
519
- // expose as empty Object, not null
520
- _nextToken = JsonToken .END_OBJECT ;
521
- _parsingContext = _parsingContext .createChildObjectContext (-1 , -1 );
522
- return (_currToken = JsonToken .START_OBJECT );
523
- }
524
- return (_currToken = JsonToken .VALUE_NULL );
525
- }
526
- _currToken = _parsingContext .inArray () ? JsonToken .END_ARRAY : JsonToken .END_OBJECT ;
527
- _parsingContext = _parsingContext .getParent ();
528
- _namesToWrap = _parsingContext .getNamesToWrap ();
529
- return _currToken ;
530
-
531
- case XmlTokenStream .XML_ATTRIBUTE_NAME :
532
- // If there was a chance of leaf node, no more...
533
- if (_mayBeLeaf ) {
534
- _mayBeLeaf = false ;
535
- _nextToken = JsonToken .FIELD_NAME ;
536
- _currText = _xmlTokens .getText ();
537
- _parsingContext = _parsingContext .createChildObjectContext (-1 , -1 );
538
- return (_currToken = JsonToken .START_OBJECT );
539
- }
540
- _parsingContext .setCurrentName (_xmlTokens .getLocalName ());
541
- return (_currToken = JsonToken .FIELD_NAME );
542
- case XmlTokenStream .XML_ATTRIBUTE_VALUE :
543
- _currText = _xmlTokens .getText ();
544
- return (_currToken = JsonToken .VALUE_STRING );
545
- case XmlTokenStream .XML_TEXT :
546
- _currText = _xmlTokens .getText ();
547
- if (_mayBeLeaf ) {
548
- _mayBeLeaf = false ;
549
- /* One more refinement (pronunced like "hack") is that if
550
- * we had an empty String (or all white space), and we are
551
- * deserializing an array, we better hide the empty text.
552
- */
553
- // Also: must skip following END_ELEMENT
554
- _xmlTokens .skipEndElement ();
555
- if (_parsingContext .inArray ()) {
556
- if (_isEmpty (_currText )) {
515
+ while (true ) {
516
+ switch (token ) {
517
+ case XmlTokenStream .XML_END_ELEMENT :
518
+ // Simple, except that if this is a leaf, need to suppress end:
519
+ if (_mayBeLeaf ) {
520
+ _mayBeLeaf = false ;
521
+ if (_parsingContext .inArray ()) {
557
522
// 06-Jan-2015, tatu: as per [dataformat-xml#180], need to
558
- // expose as empty Object, not null (or, worse, as used to
559
- // be done, by swallowing the token)
523
+ // expose as empty Object, not null
560
524
_nextToken = JsonToken .END_OBJECT ;
561
525
_parsingContext = _parsingContext .createChildObjectContext (-1 , -1 );
562
526
return (_currToken = JsonToken .START_OBJECT );
563
527
}
528
+ return (_currToken = JsonToken .VALUE_NULL );
529
+ }
530
+ _currToken = _parsingContext .inArray () ? JsonToken .END_ARRAY : JsonToken .END_OBJECT ;
531
+ _parsingContext = _parsingContext .getParent ();
532
+ _namesToWrap = _parsingContext .getNamesToWrap ();
533
+ return _currToken ;
534
+
535
+ case XmlTokenStream .XML_ATTRIBUTE_NAME :
536
+ // If there was a chance of leaf node, no more...
537
+ if (_mayBeLeaf ) {
538
+ _mayBeLeaf = false ;
539
+ _nextToken = JsonToken .FIELD_NAME ;
540
+ _currText = _xmlTokens .getText ();
541
+ _parsingContext = _parsingContext .createChildObjectContext (-1 , -1 );
542
+ return (_currToken = JsonToken .START_OBJECT );
564
543
}
544
+ _parsingContext .setCurrentName (_xmlTokens .getLocalName ());
545
+ return (_currToken = JsonToken .FIELD_NAME );
546
+ case XmlTokenStream .XML_ATTRIBUTE_VALUE :
547
+ _currText = _xmlTokens .getText ();
565
548
return (_currToken = JsonToken .VALUE_STRING );
566
- } else {
567
- // [dataformat-xml#177]: empty text may also need to be skipped
568
- if (_parsingContext .inObject ()
569
- && (_currToken != JsonToken .FIELD_NAME ) && _isEmpty (_currText )) {
570
- _currToken = JsonToken .END_OBJECT ;
571
- _parsingContext = _parsingContext .getParent ();
572
- _namesToWrap = _parsingContext .getNamesToWrap ();
573
- return _currToken ;
549
+ case XmlTokenStream .XML_TEXT :
550
+ _currText = _xmlTokens .getText ();
551
+ if (_mayBeLeaf ) {
552
+ _mayBeLeaf = false ;
553
+ // One more refinement (pronunced like "hack") is that if
554
+ // we had an empty String (or all white space), and we are
555
+ // deserializing an array, we better hide the empty text.
556
+ // Also: must skip following END_ELEMENT
557
+ _xmlTokens .skipEndElement ();
558
+ if (_parsingContext .inArray ()) {
559
+ if (_isEmpty (_currText )) {
560
+ // 06-Jan-2015, tatu: as per [dataformat-xml#180], need to
561
+ // expose as empty Object, not null (or, worse, as used to
562
+ // be done, by swallowing the token)
563
+ _nextToken = JsonToken .END_OBJECT ;
564
+ _parsingContext = _parsingContext .createChildObjectContext (-1 , -1 );
565
+ return (_currToken = JsonToken .START_OBJECT );
566
+ }
567
+ }
568
+ return (_currToken = JsonToken .VALUE_STRING );
569
+ } else {
570
+ // [dataformat-xml#177]: empty text may also need to be skipped
571
+ // but... [dataformat-xml#191]: looks like we can't short-cut, must
572
+ // loop over again
573
+ if (_parsingContext .inObject ()) {
574
+ if ((_currToken != JsonToken .FIELD_NAME ) && _isEmpty (_currText )) {
575
+ token = _xmlTokens .next ();
576
+ continue ;
577
+ }
578
+ }
574
579
}
580
+ // If not a leaf (or otherwise ignorable), need to transform into property...
581
+ _parsingContext .setCurrentName (_cfgNameForTextElement );
582
+ _nextToken = JsonToken .VALUE_STRING ;
583
+ return (_currToken = JsonToken .FIELD_NAME );
584
+ case XmlTokenStream .XML_END :
585
+ return (_currToken = null );
575
586
}
576
- // If not a leaf (or otherwise ignorable), need to transform into property...
577
- _parsingContext .setCurrentName (_cfgNameForTextElement );
578
- _nextToken = JsonToken .VALUE_STRING ;
579
- return (_currToken = JsonToken .FIELD_NAME );
580
- case XmlTokenStream .XML_END :
581
- return (_currToken = null );
582
587
}
583
-
584
- // should never get here
585
- _throwInternal ();
586
- return null ;
587
588
}
588
589
589
590
/*
0 commit comments