@@ -40,10 +40,18 @@ public class RangeDeserializer
4040 /* Life-cycle
4141 /**********************************************************
4242 */
43+
44+ /**
45+ * @deprecated Since 2.7
46+ */
47+ @ Deprecated // since 2.7
48+ public RangeDeserializer (JavaType rangeType ) {
49+ this (null , rangeType );
50+ }
4351
4452 public RangeDeserializer (BoundType defaultBoundType , JavaType rangeType ) {
4553 this (rangeType , null );
46- this . _defaultBoundType = defaultBoundType ;
54+ _defaultBoundType = defaultBoundType ;
4755 }
4856
4957 @ SuppressWarnings ("unchecked" )
@@ -90,14 +98,14 @@ public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
9098 @ Override
9199 public Object deserializeWithType (JsonParser jp , DeserializationContext ctxt ,
92100 TypeDeserializer typeDeserializer )
93- throws IOException , JsonProcessingException
101+ throws IOException
94102 {
95103 return typeDeserializer .deserializeTypedFromObject (jp , ctxt );
96104 }
97105
98106 @ Override
99107 public Range <?> deserialize (JsonParser parser , DeserializationContext context )
100- throws IOException , JsonProcessingException
108+ throws IOException
101109 {
102110 // NOTE: either START_OBJECT _or_ FIELD_NAME fine; latter for polymorphic cases
103111 JsonToken t = parser .getCurrentToken ();
@@ -107,43 +115,32 @@ public Range<?> deserialize(JsonParser parser, DeserializationContext context)
107115
108116 Comparable <?> lowerEndpoint = null ;
109117 Comparable <?> upperEndpoint = null ;
110- BoundType lowerBoundType = null ;
111- BoundType upperBoundType = null ;
118+ BoundType lowerBoundType = _defaultBoundType ;
119+ BoundType upperBoundType = _defaultBoundType ;
112120
113121 for (; t != JsonToken .END_OBJECT ; t = parser .nextToken ()) {
114122 expect (parser , JsonToken .FIELD_NAME , t );
115123 String fieldName = parser .getCurrentName ();
116124 try {
117125 if (fieldName .equals ("lowerEndpoint" )) {
118- Preconditions .checkState (lowerEndpoint == null , "'lowerEndpoint' field included multiple times." );
119126 parser .nextToken ();
120127 lowerEndpoint = deserializeEndpoint (parser , context );
121128 } else if (fieldName .equals ("upperEndpoint" )) {
122- Preconditions .checkState (upperEndpoint == null , "'upperEndpoint' field included multiple times." );
123129 parser .nextToken ();
124130 upperEndpoint = deserializeEndpoint (parser , context );
125131 } else if (fieldName .equals ("lowerBoundType" )) {
126- Preconditions .checkState (lowerBoundType == null , "'lowerBoundType' field included multiple times." );
127132 parser .nextToken ();
128133 lowerBoundType = deserializeBoundType (parser );
129134 } else if (fieldName .equals ("upperBoundType" )) {
130- Preconditions .checkState (upperBoundType == null , "'upperBoundType' field included multiple times." );
131135 parser .nextToken ();
132136 upperBoundType = deserializeBoundType (parser );
133137 } else {
134138 throw context .mappingException ("Unexpected Range field: " + fieldName );
135139 }
136140 } catch (IllegalStateException e ) {
137- throw new JsonMappingException ( e .getMessage ());
141+ throw JsonMappingException . from ( parser , e .getMessage ());
138142 }
139143 }
140-
141- if (lowerBoundType == null )
142- lowerBoundType = _defaultBoundType ;
143-
144- if (upperBoundType == null )
145- upperBoundType = _defaultBoundType ;
146-
147144 try {
148145 if ((lowerEndpoint != null ) && (upperEndpoint != null )) {
149146 Preconditions .checkState (lowerEndpoint .getClass () == upperEndpoint .getClass (),
@@ -164,7 +161,7 @@ public Range<?> deserialize(JsonParser parser, DeserializationContext context)
164161 }
165162 return RangeFactory .all ();
166163 } catch (IllegalStateException e ) {
167- throw new JsonMappingException ( e .getMessage ());
164+ throw JsonMappingException . from ( parser , e .getMessage ());
168165 }
169166 }
170167
@@ -190,10 +187,10 @@ private Comparable<?> deserializeEndpoint(JsonParser parser, DeserializationCont
190187 return (Comparable <?>) obj ;
191188 }
192189
193- private void expect (JsonParser jp , JsonToken expected , JsonToken actual ) throws JsonMappingException
190+ private void expect (JsonParser p , JsonToken expected , JsonToken actual ) throws JsonMappingException
194191 {
195192 if (actual != expected ) {
196- throw new JsonMappingException ( "Expecting " + expected + ", found " + actual , jp . getCurrentLocation () );
193+ throw JsonMappingException . from ( p , "Expecting " + expected + ", found " + actual );
197194 }
198195 }
199196}
0 commit comments