@@ -273,16 +273,22 @@ public JsonToken nextToken() throws IOException
273
273
_exposedContext = null ;
274
274
if (ctxt .inArray ()) {
275
275
t = delegate .getCurrentToken ();
276
- // Is this guaranteed to work without further checks?
277
- // if (t != JsonToken.START_ARRAY) {
278
276
_currToken = t ;
277
+ if (_currToken == JsonToken .END_ARRAY ) {
278
+ _headContext = _headContext .getParent ();
279
+ _itemFilter = _headContext .getFilter ();
280
+ }
279
281
return t ;
280
282
}
281
283
282
284
// 19-Jul-2021, tatu: [core#700]: following was commented out?!
283
285
// Almost! Most likely still have the current token;
284
286
// with the sole exception of FIELD_NAME
285
287
t = delegate .currentToken ();
288
+ if (t == JsonToken .END_OBJECT ) {
289
+ _headContext = _headContext .getParent ();
290
+ _itemFilter = _headContext .getFilter ();
291
+ }
286
292
if (t != JsonToken .FIELD_NAME ) {
287
293
_currToken = t ;
288
294
return t ;
@@ -562,12 +568,15 @@ protected final JsonToken _nextToken2() throws IOException
562
568
continue main_loop ;
563
569
564
570
case ID_END_ARRAY :
565
- case ID_END_OBJECT :
566
571
{
567
572
boolean returnEnd = _headContext .isStartHandled ();
568
573
f = _headContext .getFilter ();
569
574
if ((f != null ) && (f != TokenFilter .INCLUDE_ALL )) {
575
+ boolean includeEmpty = f .includeEmptyArray (_headContext .hasCurrentIndex ());
570
576
f .filterFinishArray ();
577
+ if (includeEmpty ) {
578
+ return _nextBuffered (_headContext );
579
+ }
571
580
}
572
581
_headContext = _headContext .getParent ();
573
582
_itemFilter = _headContext .getFilter ();
@@ -576,6 +585,23 @@ protected final JsonToken _nextToken2() throws IOException
576
585
}
577
586
}
578
587
continue main_loop ;
588
+ case ID_END_OBJECT :
589
+ {
590
+ boolean returnEnd = _headContext .isStartHandled ();
591
+ f = _headContext .getFilter ();
592
+ if ((f != null ) && (f != TokenFilter .INCLUDE_ALL )) {
593
+ boolean includeEmpty = f .includeEmptyArray (_headContext .hasCurrentName ());
594
+ f .filterFinishObject ();
595
+ if (includeEmpty ) {
596
+ return _nextBuffered (_headContext );
597
+ } }
598
+ _headContext = _headContext .getParent ();
599
+ _itemFilter = _headContext .getFilter ();
600
+ if (returnEnd ) {
601
+ return (_currToken = t );
602
+ }
603
+ }
604
+ continue main_loop ;
579
605
580
606
case ID_FIELD_NAME :
581
607
{
@@ -708,13 +734,16 @@ protected final JsonToken _nextTokenWithBuffering(final TokenFilterContext buffR
708
734
continue main_loop ;
709
735
710
736
case ID_END_ARRAY :
711
- case ID_END_OBJECT :
712
737
{
713
738
// Unlike with other loops, here we know that content was NOT
714
739
// included (won't get this far otherwise)
715
740
f = _headContext .getFilter ();
716
741
if ((f != null ) && (f != TokenFilter .INCLUDE_ALL )) {
742
+ boolean includeEmpty = f .includeEmptyArray (_headContext .hasCurrentIndex ());
717
743
f .filterFinishArray ();
744
+ if (includeEmpty ) {
745
+ return _nextBuffered (buffRoot );
746
+ }
718
747
}
719
748
boolean gotEnd = (_headContext == buffRoot );
720
749
boolean returnEnd = gotEnd && _headContext .isStartHandled ();
@@ -727,6 +756,33 @@ protected final JsonToken _nextTokenWithBuffering(final TokenFilterContext buffR
727
756
}
728
757
}
729
758
continue main_loop ;
759
+ case ID_END_OBJECT :
760
+ {
761
+ // Unlike with other loops, here we know that content was NOT
762
+ // included (won't get this far otherwise)
763
+ f = _headContext .getFilter ();
764
+ if ((f != null ) && (f != TokenFilter .INCLUDE_ALL )) {
765
+ boolean includeEmpty = f .includeEmptyObject (_headContext .hasCurrentName ());
766
+ f .filterFinishObject ();
767
+ if (includeEmpty ) {
768
+ _headContext ._currentName = _headContext ._parent == null
769
+ ? null
770
+ : _headContext ._parent ._currentName ;
771
+ _headContext ._needToHandleName = false ;
772
+ return _nextBuffered (buffRoot );
773
+ }
774
+ }
775
+ boolean gotEnd = (_headContext == buffRoot );
776
+ boolean returnEnd = gotEnd && _headContext .isStartHandled ();
777
+
778
+ _headContext = _headContext .getParent ();
779
+ _itemFilter = _headContext .getFilter ();
780
+
781
+ if (returnEnd ) {
782
+ return t ;
783
+ }
784
+ }
785
+ continue main_loop ;
730
786
731
787
case ID_FIELD_NAME :
732
788
{
0 commit comments