@@ -574,16 +574,22 @@ public JsonLocation getTokenLocation() {
574
574
/**
575
575
* Since xml representation can not really distinguish between array
576
576
* and object starts (both are represented with elements), this method
577
- * is overridden and taken to mean that expecation is that the current
577
+ * is overridden and taken to mean that expectation is that the current
578
578
* start element is to mean 'start array', instead of default of
579
579
* 'start object'.
580
+ *
581
+ * @throws UncheckedIOException if underlying {@link StreamReadConstraints} constraint fails
580
582
*/
581
583
@ Override
582
584
public boolean isExpectedStartArrayToken ()
583
585
{
584
586
JsonToken t = _currToken ;
585
587
if (t == JsonToken .START_OBJECT ) {
586
- _currToken = JsonToken .START_ARRAY ;
588
+ try {
589
+ _updateToken (JsonToken .START_ARRAY );
590
+ } catch (StreamConstraintsException e ) {
591
+ throw new UncheckedIOException (e );
592
+ }
587
593
// Ok: must replace current context with array as well
588
594
_parsingContext .convertToArray ();
589
595
//System.out.println(" FromXmlParser.isExpectedArrayStart(): OBJ->Array");
@@ -607,6 +613,8 @@ public boolean isExpectedStartArrayToken()
607
613
* scalar types (numbers, booleans) -- they are all just Character Data,
608
614
* without schema -- we can try to infer type from intent here.
609
615
* The main benefit is avoiding checks for coercion.
616
+ *
617
+ * @throws UncheckedIOException if underlying {@link StreamReadConstraints} constraint fails
610
618
*/
611
619
@ Override
612
620
public boolean isExpectedNumberIntToken ()
@@ -615,57 +623,57 @@ public boolean isExpectedNumberIntToken()
615
623
if (t == JsonToken .VALUE_STRING ) {
616
624
final String text = _currText .trim ();
617
625
final int len = _isIntNumber (text );
618
- if (len > 0 ) {
619
- if (len <= 9 ) {
620
- _numberInt = NumberInput .parseInt (text );
621
- _numTypesValid = NR_INT ;
622
- _currToken = JsonToken .VALUE_NUMBER_INT ;
623
- return true ;
624
- }
625
- if (len <= 18 ) { // definitely in long range
626
- long l = NumberInput .parseLong (text );
627
- if (len == 10 ) {
628
- int asInt = (int ) l ;
629
- long l2 = (long ) asInt ;
630
- if (l == l2 ) {
631
- _numberInt = asInt ;
632
- _numTypesValid = NR_INT ;
633
- _currToken = JsonToken .VALUE_NUMBER_INT ;
634
- return true ;
635
- }
636
- }
637
- _numberLong = l ;
638
- _numTypesValid = NR_LONG ;
639
- _currToken = JsonToken .VALUE_NUMBER_INT ;
640
- return true ;
641
- }
642
- // Might still fit within `long`
643
- if (len == 19 ) {
644
- final boolean stillLong ;
645
- if (text .charAt (0 ) == '-' ) {
646
- stillLong = NumberInput .inLongRange (text .substring (1 ), true );
647
- } else {
648
- stillLong = NumberInput .inLongRange (text , false );
626
+ try {
627
+ if (len > 0 ) {
628
+ if (len <= 9 ) {
629
+ _numberInt = NumberInput .parseInt (text );
630
+ _numTypesValid = NR_INT ;
631
+ _updateToken (JsonToken .VALUE_NUMBER_INT );
632
+ return true ;
649
633
}
650
- if (stillLong ) {
651
- _numberLong = NumberInput .parseLong (text );
634
+ if (len <= 18 ) { // definitely in long range
635
+ long l = NumberInput .parseLong (text );
636
+ if (len == 10 ) {
637
+ int asInt = (int ) l ;
638
+ long l2 = (long ) asInt ;
639
+ if (l == l2 ) {
640
+ _numberInt = asInt ;
641
+ _numTypesValid = NR_INT ;
642
+ _updateToken (JsonToken .VALUE_NUMBER_INT );
643
+ return true ;
644
+ }
645
+ }
646
+ _numberLong = l ;
652
647
_numTypesValid = NR_LONG ;
653
- _currToken = JsonToken .VALUE_NUMBER_INT ;
648
+ _updateToken ( JsonToken .VALUE_NUMBER_INT ) ;
654
649
return true ;
655
650
}
656
- }
657
- // finally, need BigInteger
658
- try {
651
+ // Might still fit within `long`
652
+ if (len == 19 ) {
653
+ final boolean stillLong ;
654
+ if (text .charAt (0 ) == '-' ) {
655
+ stillLong = NumberInput .inLongRange (text .substring (1 ), true );
656
+ } else {
657
+ stillLong = NumberInput .inLongRange (text , false );
658
+ }
659
+ if (stillLong ) {
660
+ _numberLong = NumberInput .parseLong (text );
661
+ _numTypesValid = NR_LONG ;
662
+ _updateToken (JsonToken .VALUE_NUMBER_INT );
663
+ return true ;
664
+ }
665
+ }
666
+ // finally, need BigInteger
659
667
streamReadConstraints ().validateIntegerLength (text .length ());
660
- } catch (StreamConstraintsException e ) {
661
- // Ugh. This method in API ought to expose IOException
662
- throw new UncheckedIOException (e );
663
- }
664
- _numberBigInt = NumberInput .parseBigInteger (
668
+ _numberBigInt = NumberInput .parseBigInteger (
665
669
text , isEnabled (StreamReadFeature .USE_FAST_BIG_NUMBER_PARSER ));
666
- _numTypesValid = NR_BIGINT ;
667
- _currToken = JsonToken .VALUE_NUMBER_INT ;
668
- return true ;
670
+ _numTypesValid = NR_BIGINT ;
671
+ _updateToken (JsonToken .VALUE_NUMBER_INT );
672
+ return true ;
673
+ }
674
+ } catch (StreamConstraintsException e ) {
675
+ // Ugh. This method in API ought to expose IOException
676
+ throw new UncheckedIOException (e );
669
677
}
670
678
}
671
679
return (t == JsonToken .VALUE_NUMBER_INT );
@@ -702,8 +710,7 @@ public JsonToken nextToken() throws IOException
702
710
_numTypesValid = NR_UNKNOWN ;
703
711
//System.out.println("FromXmlParser.nextToken0: _nextToken = "+_nextToken);
704
712
if (_nextToken != null ) {
705
- JsonToken t = _nextToken ;
706
- _currToken = t ;
713
+ final JsonToken t = _updateToken (_nextToken );
707
714
_nextToken = null ;
708
715
709
716
switch (t ) {
@@ -745,7 +752,7 @@ public JsonToken nextToken() throws IOException
745
752
// leave _mayBeLeaf set, as we start a new context
746
753
_nextToken = JsonToken .FIELD_NAME ;
747
754
_parsingContext = _parsingContext .createChildObjectContext (-1 , -1 );
748
- return ( _currToken = JsonToken .START_OBJECT );
755
+ return _updateToken ( JsonToken .START_OBJECT );
749
756
}
750
757
if (_parsingContext .inArray ()) {
751
758
// Yup: in array, so this element could be verified; but it won't be
@@ -766,7 +773,7 @@ public JsonToken nextToken() throws IOException
766
773
_mayBeLeaf = true ;
767
774
// Ok: in array context we need to skip reporting field names.
768
775
// But what's the best way to find next token?
769
- return ( _currToken = JsonToken .FIELD_NAME );
776
+ return _updateToken ( JsonToken .FIELD_NAME );
770
777
}
771
778
772
779
// Ok; beyond start element, what do we get?
@@ -781,16 +788,16 @@ public JsonToken nextToken() throws IOException
781
788
// expose as empty Object, not null
782
789
_nextToken = JsonToken .END_OBJECT ;
783
790
_parsingContext = _parsingContext .createChildObjectContext (-1 , -1 );
784
- return ( _currToken = JsonToken .START_OBJECT );
791
+ return _updateToken ( JsonToken .START_OBJECT );
785
792
}
786
793
// 07-Sep-2019, tatu: for [dataformat-xml#353], must NOT return second null
787
794
if (_currToken != JsonToken .VALUE_NULL ) {
788
795
// 13-May-2020, tatu: [dataformat-xml#397]: advance `index`
789
796
_parsingContext .valueStarted ();
790
- return ( _currToken = JsonToken .VALUE_NULL );
797
+ return _updateToken ( JsonToken .VALUE_NULL );
791
798
}
792
799
}
793
- _currToken = _parsingContext .inArray () ? JsonToken .END_ARRAY : JsonToken .END_OBJECT ;
800
+ _updateToken ( _parsingContext .inArray () ? JsonToken .END_ARRAY : JsonToken .END_OBJECT ) ;
794
801
_parsingContext = _parsingContext .getParent ();
795
802
return _currToken ;
796
803
@@ -801,15 +808,15 @@ public JsonToken nextToken() throws IOException
801
808
_nextToken = JsonToken .FIELD_NAME ;
802
809
_currText = _xmlTokens .getText ();
803
810
_parsingContext = _parsingContext .createChildObjectContext (-1 , -1 );
804
- return ( _currToken = JsonToken .START_OBJECT );
811
+ return _updateToken ( JsonToken .START_OBJECT );
805
812
}
806
813
_parsingContext .setCurrentName (_xmlTokens .getLocalName ());
807
- return ( _currToken = JsonToken .FIELD_NAME );
814
+ return _updateToken ( JsonToken .FIELD_NAME );
808
815
case XmlTokenStream .XML_ATTRIBUTE_VALUE :
809
816
_currText = _xmlTokens .getText ();
810
817
// 13-May-2020, tatu: [dataformat-xml#397]: advance `index`
811
818
_parsingContext .valueStarted ();
812
- return ( _currToken = JsonToken .VALUE_STRING );
819
+ return _updateToken ( JsonToken .VALUE_STRING );
813
820
case XmlTokenStream .XML_TEXT :
814
821
_currText = _xmlTokens .getText ();
815
822
if (_mayBeLeaf ) {
@@ -831,10 +838,10 @@ public JsonToken nextToken() throws IOException
831
838
// be done, by swallowing the token)
832
839
_nextToken = JsonToken .END_OBJECT ;
833
840
_parsingContext = _parsingContext .createChildObjectContext (-1 , -1 );
834
- return ( _currToken = JsonToken .START_OBJECT );
841
+ return _updateToken ( JsonToken .START_OBJECT );
835
842
}
836
843
}
837
- return ( _currToken = JsonToken .VALUE_STRING );
844
+ return _updateToken ( JsonToken .VALUE_STRING );
838
845
}
839
846
if (token != XmlTokenStream .XML_START_ELEMENT ) {
840
847
throw new JsonParseException (this , String .format (
@@ -856,7 +863,7 @@ public JsonToken nextToken() throws IOException
856
863
// along is not enough.
857
864
_nextIsLeadingMixed = true ;
858
865
_nextToken = JsonToken .FIELD_NAME ;
859
- return ( _currToken = JsonToken .START_OBJECT );
866
+ return _updateToken ( JsonToken .START_OBJECT );
860
867
} else if (XmlTokenStream ._allWs (_currText )) {
861
868
token = _nextToken ();
862
869
continue ;
@@ -885,9 +892,9 @@ public JsonToken nextToken() throws IOException
885
892
// If not a leaf (or otherwise ignorable), need to transform into property...
886
893
_parsingContext .setCurrentName (_cfgNameForTextElement );
887
894
_nextToken = JsonToken .VALUE_STRING ;
888
- return ( _currToken = JsonToken .FIELD_NAME );
895
+ return _updateToken ( JsonToken .FIELD_NAME );
889
896
case XmlTokenStream .XML_END :
890
- return ( _currToken = null );
897
+ return _updateToken ( null );
891
898
default :
892
899
return _internalErrorUnknownToken (token );
893
900
}
@@ -919,8 +926,7 @@ public String nextTextValue() throws IOException
919
926
{
920
927
_binaryValue = null ;
921
928
if (_nextToken != null ) {
922
- JsonToken t = _nextToken ;
923
- _currToken = t ;
929
+ final JsonToken t = _updateToken (_nextToken );
924
930
_nextToken = null ;
925
931
926
932
// expected case; yes, got a String
@@ -940,7 +946,7 @@ public String nextTextValue() throws IOException
940
946
if (_mayBeLeaf ) {
941
947
_nextToken = JsonToken .FIELD_NAME ;
942
948
_parsingContext = _parsingContext .createChildObjectContext (-1 , -1 );
943
- _currToken = JsonToken .START_OBJECT ;
949
+ _updateToken ( JsonToken .START_OBJECT ) ;
944
950
return null ;
945
951
}
946
952
if (_parsingContext .inArray ()) {
@@ -955,7 +961,7 @@ public String nextTextValue() throws IOException
955
961
_xmlTokens .repeatStartElement ();
956
962
}
957
963
_mayBeLeaf = true ;
958
- _currToken = JsonToken .FIELD_NAME ;
964
+ _updateToken ( JsonToken .FIELD_NAME ) ;
959
965
return null ;
960
966
}
961
967
@@ -969,12 +975,12 @@ public String nextTextValue() throws IOException
969
975
// asked text value -- but that seems incorrect. Hoping this won't
970
976
// break anything in 2.15+
971
977
972
- _currToken = JsonToken .VALUE_NULL ;
978
+ _updateToken ( JsonToken .VALUE_NULL ) ;
973
979
// 13-May-2020, tatu: [dataformat-xml#397]: advance `index`
974
980
_parsingContext .valueStarted ();
975
981
return (_currText = null );
976
982
}
977
- _currToken = _parsingContext .inArray () ? JsonToken .END_ARRAY : JsonToken .END_OBJECT ;
983
+ _updateToken ( _parsingContext .inArray () ? JsonToken .END_ARRAY : JsonToken .END_OBJECT ) ;
978
984
_parsingContext = _parsingContext .getParent ();
979
985
break ;
980
986
case XmlTokenStream .XML_ATTRIBUTE_NAME :
@@ -984,14 +990,14 @@ public String nextTextValue() throws IOException
984
990
_nextToken = JsonToken .FIELD_NAME ;
985
991
_currText = _xmlTokens .getText ();
986
992
_parsingContext = _parsingContext .createChildObjectContext (-1 , -1 );
987
- _currToken = JsonToken .START_OBJECT ;
993
+ _updateToken ( JsonToken .START_OBJECT ) ;
988
994
} else {
989
995
_parsingContext .setCurrentName (_xmlTokens .getLocalName ());
990
- _currToken = JsonToken .FIELD_NAME ;
996
+ _updateToken ( JsonToken .FIELD_NAME ) ;
991
997
}
992
998
break ;
993
999
case XmlTokenStream .XML_ATTRIBUTE_VALUE :
994
- _currToken = JsonToken .VALUE_STRING ;
1000
+ _updateToken ( JsonToken .VALUE_STRING ) ;
995
1001
// 13-May-2020, tatu: [dataformat-xml#397]: advance `index`
996
1002
_parsingContext .valueStarted ();
997
1003
return (_currText = _xmlTokens .getText ());
@@ -1005,16 +1011,16 @@ public String nextTextValue() throws IOException
1005
1011
// for otherwise empty List/array
1006
1012
// 13-May-2020, tatu: [dataformat-xml#397]: advance `index`
1007
1013
_parsingContext .valueStarted ();
1008
- _currToken = JsonToken .VALUE_STRING ;
1014
+ _updateToken ( JsonToken .VALUE_STRING ) ;
1009
1015
return _currText ;
1010
1016
}
1011
1017
// If not a leaf, need to transform into property...
1012
1018
_parsingContext .setCurrentName (_cfgNameForTextElement );
1013
1019
_nextToken = JsonToken .VALUE_STRING ;
1014
- _currToken = JsonToken .FIELD_NAME ;
1020
+ _updateToken ( JsonToken .FIELD_NAME ) ;
1015
1021
break ;
1016
1022
case XmlTokenStream .XML_END :
1017
- _currToken = null ;
1023
+ _updateTokenToNull () ;
1018
1024
default :
1019
1025
return _internalErrorUnknownToken (token );
1020
1026
}
0 commit comments