@@ -729,346 +729,15 @@ protected Object _deserializeFP(JsonParser p, DeserializationContext ctxt) throw
729
729
return p .getDoubleValue ();
730
730
}
731
731
732
- /*
733
- /**********************************************************************
734
- /* Separate "vanilla" implementation for common case of no deser overrides
735
- /**********************************************************************
736
- */
737
-
738
- /**
739
- * Streamlined version of {@link UntypedObjectDeserializer} that has fewer checks and
740
- * is only used when no custom deserializer overrides are applied.
741
- */
742
- @ JacksonStdImpl
743
- @ Deprecated // since 2.14, to be removed in near future
744
- public static class Vanilla
745
- extends StdDeserializer <Object >
746
- {
747
- private static final long serialVersionUID = 1L ;
748
-
749
- public final static Vanilla std = new Vanilla ();
750
-
751
- // @since 2.9
752
- protected final boolean _nonMerging ;
753
-
754
- public Vanilla () { this (false ); }
755
-
756
- protected Vanilla (boolean nonMerging ) {
757
- super (Object .class );
758
- _nonMerging = nonMerging ;
759
- }
760
-
761
- public static Vanilla instance (boolean nonMerging ) {
762
- if (nonMerging ) {
763
- return new Vanilla (true );
764
- }
765
- return std ;
766
- }
767
-
768
- @ Override // since 2.12
769
- public LogicalType logicalType () {
770
- return LogicalType .Untyped ;
771
- }
772
732
773
- @ Override // since 2.9
774
- public Boolean supportsUpdate (DeserializationConfig config ) {
775
- // 21-Apr-2017, tatu: Bit tricky... some values, yes. So let's say "dunno"
776
- // 14-Jun-2017, tatu: Well, if merging blocked, can say no, as well.
777
- return _nonMerging ? Boolean .FALSE : null ;
778
- }
779
-
780
- @ Override
781
- public Object deserialize (JsonParser p , DeserializationContext ctxt ) throws IOException
782
- {
783
- switch (p .currentTokenId ()) {
784
- case JsonTokenId .ID_START_OBJECT :
785
- {
786
- JsonToken t = p .nextToken ();
787
- if (t == JsonToken .END_OBJECT ) {
788
- return new LinkedHashMap <String ,Object >(2 );
789
- }
790
- }
791
- case JsonTokenId .ID_FIELD_NAME :
792
- return mapObject (p , ctxt );
793
- case JsonTokenId .ID_START_ARRAY :
794
- {
795
- JsonToken t = p .nextToken ();
796
- if (t == JsonToken .END_ARRAY ) { // and empty one too
797
- if (ctxt .isEnabled (DeserializationFeature .USE_JAVA_ARRAY_FOR_JSON_ARRAY )) {
798
- return NO_OBJECTS ;
799
- }
800
- return new ArrayList <Object >(2 );
801
- }
802
- }
803
- if (ctxt .isEnabled (DeserializationFeature .USE_JAVA_ARRAY_FOR_JSON_ARRAY )) {
804
- return mapArrayToArray (p , ctxt );
805
- }
806
- return mapArray (p , ctxt );
807
- case JsonTokenId .ID_EMBEDDED_OBJECT :
808
- return p .getEmbeddedObject ();
809
- case JsonTokenId .ID_STRING :
810
- return p .getText ();
811
-
812
- case JsonTokenId .ID_NUMBER_INT :
813
- if (ctxt .hasSomeOfFeatures (F_MASK_INT_COERCIONS )) {
814
- return _coerceIntegral (p , ctxt );
815
- }
816
- return p .getNumberValue (); // should be optimal, whatever it is
817
-
818
- case JsonTokenId .ID_NUMBER_FLOAT :
819
- return _deserializeFP (p , ctxt );
820
-
821
- case JsonTokenId .ID_TRUE :
822
- return Boolean .TRUE ;
823
- case JsonTokenId .ID_FALSE :
824
- return Boolean .FALSE ;
825
-
826
- case JsonTokenId .ID_END_OBJECT :
827
- // 28-Oct-2015, tatu: [databind#989] We may also be given END_OBJECT (similar to FIELD_NAME),
828
- // if caller has advanced to the first token of Object, but for empty Object
829
- return new LinkedHashMap <String ,Object >(2 );
830
-
831
- case JsonTokenId .ID_NULL : // 08-Nov-2016, tatu: yes, occurs
832
- return null ;
833
-
834
- //case JsonTokenId.ID_END_ARRAY: // invalid
835
- default :
836
- }
837
- return ctxt .handleUnexpectedToken (Object .class , p );
838
- }
839
-
840
- @ Override
841
- public Object deserializeWithType (JsonParser p , DeserializationContext ctxt , TypeDeserializer typeDeserializer ) throws IOException
842
- {
843
- switch (p .currentTokenId ()) {
844
- case JsonTokenId .ID_START_ARRAY :
845
- case JsonTokenId .ID_START_OBJECT :
846
- case JsonTokenId .ID_FIELD_NAME :
847
- return typeDeserializer .deserializeTypedFromAny (p , ctxt );
848
-
849
- case JsonTokenId .ID_STRING :
850
- return p .getText ();
851
-
852
- case JsonTokenId .ID_NUMBER_INT :
853
- if (ctxt .isEnabled (DeserializationFeature .USE_BIG_INTEGER_FOR_INTS )) {
854
- return p .getBigIntegerValue ();
855
- }
856
- return p .getNumberValue ();
857
-
858
- case JsonTokenId .ID_NUMBER_FLOAT :
859
- return _deserializeFP (p , ctxt );
860
-
861
- case JsonTokenId .ID_TRUE :
862
- return Boolean .TRUE ;
863
- case JsonTokenId .ID_FALSE :
864
- return Boolean .FALSE ;
865
- case JsonTokenId .ID_EMBEDDED_OBJECT :
866
- return p .getEmbeddedObject ();
867
-
868
- case JsonTokenId .ID_NULL : // should not get this far really but...
869
- return null ;
870
- default :
871
- }
872
- return ctxt .handleUnexpectedToken (Object .class , p );
873
- }
874
-
875
- @ SuppressWarnings ("unchecked" )
876
- @ Override // since 2.9 (to support deep merge)
877
- public Object deserialize (JsonParser p , DeserializationContext ctxt , Object intoValue )
878
- throws IOException
879
- {
880
- if (_nonMerging ) {
881
- return deserialize (p , ctxt );
882
- }
883
- switch (p .currentTokenId ()) {
884
- case JsonTokenId .ID_END_OBJECT :
885
- case JsonTokenId .ID_END_ARRAY :
886
- return intoValue ;
887
- case JsonTokenId .ID_START_OBJECT :
888
- {
889
- JsonToken t = p .nextToken (); // to get to FIELD_NAME or END_OBJECT
890
- if (t == JsonToken .END_OBJECT ) {
891
- return intoValue ;
892
- }
893
- }
894
- case JsonTokenId .ID_FIELD_NAME :
895
- if (intoValue instanceof Map <?,?>) {
896
- Map <Object ,Object > m = (Map <Object ,Object >) intoValue ;
897
- // NOTE: we are guaranteed to point to FIELD_NAME
898
- String key = p .currentName ();
899
- do {
900
- p .nextToken ();
901
- // and possibly recursive merge here
902
- Object old = m .get (key );
903
- Object newV ;
904
- if (old != null ) {
905
- newV = deserialize (p , ctxt , old );
906
- } else {
907
- newV = deserialize (p , ctxt );
908
- }
909
- if (newV != old ) {
910
- m .put (key , newV );
911
- }
912
- } while ((key = p .nextFieldName ()) != null );
913
- return intoValue ;
914
- }
915
- break ;
916
- case JsonTokenId .ID_START_ARRAY :
917
- {
918
- JsonToken t = p .nextToken (); // to get to FIELD_NAME or END_OBJECT
919
- if (t == JsonToken .END_ARRAY ) {
920
- return intoValue ;
921
- }
922
- }
923
-
924
- if (intoValue instanceof Collection <?>) {
925
- Collection <Object > c = (Collection <Object >) intoValue ;
926
- // NOTE: merge for arrays/Collections means append, can't merge contents
927
- do {
928
- c .add (deserialize (p , ctxt ));
929
- } while (p .nextToken () != JsonToken .END_ARRAY );
930
- return intoValue ;
931
- }
932
- // 21-Apr-2017, tatu: Should we try to support merging of Object[] values too?
933
- // ... maybe future improvement
934
- break ;
935
- }
936
- // Easiest handling for the rest, delegate. Only (?) question: how about nulls?
937
- return deserialize (p , ctxt );
938
- }
939
-
940
- // @since 2.17
941
- protected Object _deserializeFP (JsonParser p , DeserializationContext ctxt ) throws IOException
942
- {
943
- JsonParser .NumberTypeFP nt = p .getNumberTypeFP ();
944
- if (nt == JsonParser .NumberTypeFP .BIG_DECIMAL ) {
945
- return p .getDecimalValue ();
946
- }
947
- if (!p .isNaN ()) {
948
- if (ctxt .isEnabled (DeserializationFeature .USE_BIG_DECIMAL_FOR_FLOATS )) {
949
- return p .getDecimalValue ();
950
- }
951
- }
952
- if (nt == JsonParser .NumberTypeFP .FLOAT32 ) {
953
- return p .getFloatValue ();
954
- }
955
- return p .getDoubleValue ();
956
- }
957
-
958
- protected Object mapArray (JsonParser p , DeserializationContext ctxt ) throws IOException
959
- {
960
- Object value = deserialize (p , ctxt );
961
- if (p .nextToken () == JsonToken .END_ARRAY ) {
962
- ArrayList <Object > l = new ArrayList <Object >(2 );
963
- l .add (value );
964
- return l ;
965
- }
966
- ObjectBuffer buffer = ctxt .leaseObjectBuffer ();
967
- Object [] values = buffer .resetAndStart ();
968
- int ptr = 0 ;
969
- values [ptr ++] = value ;
970
- int totalSize = ptr ;
971
- do {
972
- value = deserialize (p , ctxt );
973
- ++totalSize ;
974
- if (ptr >= values .length ) {
975
- values = buffer .appendCompletedChunk (values );
976
- ptr = 0 ;
977
- }
978
- values [ptr ++] = value ;
979
- } while (p .nextToken () != JsonToken .END_ARRAY );
980
- // let's create full array then
981
- ArrayList <Object > result = new ArrayList <Object >(totalSize );
982
- buffer .completeAndClearBuffer (values , ptr , result );
983
- ctxt .returnObjectBuffer (buffer );
984
- return result ;
985
- }
986
-
987
- protected Object [] mapArrayToArray (JsonParser p , DeserializationContext ctxt ) throws IOException {
988
- ObjectBuffer buffer = ctxt .leaseObjectBuffer ();
989
- Object [] values = buffer .resetAndStart ();
990
- int ptr = 0 ;
991
- do {
992
- Object value = deserialize (p , ctxt );
993
- if (ptr >= values .length ) {
994
- values = buffer .appendCompletedChunk (values );
995
- ptr = 0 ;
996
- }
997
- values [ptr ++] = value ;
998
- } while (p .nextToken () != JsonToken .END_ARRAY );
999
- Object [] result = buffer .completeAndClearBuffer (values , ptr );
1000
- ctxt .returnObjectBuffer (buffer );
1001
- return result ;
1002
- }
1003
-
1004
- protected Object mapObject (JsonParser p , DeserializationContext ctxt ) throws IOException
1005
- {
1006
- // will point to FIELD_NAME at this point, guaranteed
1007
- // 19-Jul-2021, tatu: Was incorrectly using "getText()" before 2.13, fixed for 2.13.0
1008
- String key1 = p .currentName ();
1009
- p .nextToken ();
1010
- Object value1 = deserialize (p , ctxt );
1011
-
1012
- String key = p .nextFieldName ();
1013
- if (key == null ) { // single entry; but we want modifiable
1014
- LinkedHashMap <String , Object > result = new LinkedHashMap <String , Object >(2 );
1015
- result .put (key1 , value1 );
1016
- return result ;
1017
- }
1018
- // And then the general case; default map size is 16
1019
- LinkedHashMap <String , Object > result = new LinkedHashMap <String , Object >();
1020
- result .put (key1 , value1 );
1021
- do {
1022
- p .nextToken ();
1023
- final Object newValue = deserialize (p , ctxt );
1024
- final Object oldValue = result .put (key , newValue );
1025
- if (oldValue != null ) {
1026
- return _mapObjectWithDups (p , ctxt , result , key , oldValue , newValue ,
1027
- p .nextFieldName ());
1028
- }
1029
- } while ((key = p .nextFieldName ()) != null );
1030
- return result ;
1031
- }
1032
-
1033
- // NOTE: copied from above (alas, no easy way to share/reuse)
1034
- // @since 2.12 (wrt [databind#2733]
1035
- protected Object _mapObjectWithDups (JsonParser p , DeserializationContext ctxt ,
1036
- final Map <String , Object > result , String initialKey ,
1037
- Object oldValue , Object newValue , String nextKey ) throws IOException
1038
- {
1039
- final boolean squashDups = ctxt .isEnabled (StreamReadCapability .DUPLICATE_PROPERTIES );
1040
-
1041
- if (squashDups ) {
1042
- _squashDups (result , initialKey , oldValue , newValue );
1043
- }
1044
-
1045
- while (nextKey != null ) {
1046
- p .nextToken ();
1047
- newValue = deserialize (p , ctxt );
1048
- oldValue = result .put (nextKey , newValue );
1049
- if ((oldValue != null ) && squashDups ) {
1050
- _squashDups (result , nextKey , oldValue , newValue );
1051
- }
1052
- nextKey = p .nextFieldName ();
1053
- }
1054
-
1055
- return result ;
1056
- }
1057
-
1058
- // NOTE: copied from above (alas, no easy way to share/reuse)
1059
- @ SuppressWarnings ("unchecked" )
1060
- private void _squashDups (final Map <String , Object > result , String key ,
1061
- Object oldValue , Object newValue )
1062
- {
1063
- if (oldValue instanceof List <?>) {
1064
- ((List <Object >) oldValue ).add (newValue );
1065
- result .put (key , oldValue );
1066
- } else {
1067
- ArrayList <Object > l = new ArrayList <>();
1068
- l .add (oldValue );
1069
- l .add (newValue );
1070
- result .put (key , l );
1071
- }
1072
- }
1073
- }
1074
- }
733
+ // Separate "vanilla" implementation for common case of no deser overrides
734
+ // Streamlined version of {@link UntypedObjectDeserializer} that has fewer checks and
735
+ // is only used when no custom deserializer overrides are applied.
736
+ //
737
+ //@JacksonStdImpl
738
+ //@Deprecated // since 2.14, to be removed in near future
739
+ //
740
+ // Was removed from 2.19
741
+ //
742
+ // public static class Vanilla extends StdDeserializer<Object> { }
743
+ }
0 commit comments