@@ -40,10 +40,18 @@ public class RangeDeserializer
40
40
/* Life-cycle
41
41
/**********************************************************
42
42
*/
43
+
44
+ /**
45
+ * @deprecated Since 2.7
46
+ */
47
+ @ Deprecated // since 2.7
48
+ public RangeDeserializer (JavaType rangeType ) {
49
+ this (null , rangeType );
50
+ }
43
51
44
52
public RangeDeserializer (BoundType defaultBoundType , JavaType rangeType ) {
45
53
this (rangeType , null );
46
- this . _defaultBoundType = defaultBoundType ;
54
+ _defaultBoundType = defaultBoundType ;
47
55
}
48
56
49
57
@ SuppressWarnings ("unchecked" )
@@ -90,14 +98,14 @@ public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
90
98
@ Override
91
99
public Object deserializeWithType (JsonParser jp , DeserializationContext ctxt ,
92
100
TypeDeserializer typeDeserializer )
93
- throws IOException , JsonProcessingException
101
+ throws IOException
94
102
{
95
103
return typeDeserializer .deserializeTypedFromObject (jp , ctxt );
96
104
}
97
105
98
106
@ Override
99
107
public Range <?> deserialize (JsonParser parser , DeserializationContext context )
100
- throws IOException , JsonProcessingException
108
+ throws IOException
101
109
{
102
110
// NOTE: either START_OBJECT _or_ FIELD_NAME fine; latter for polymorphic cases
103
111
JsonToken t = parser .getCurrentToken ();
@@ -107,43 +115,32 @@ public Range<?> deserialize(JsonParser parser, DeserializationContext context)
107
115
108
116
Comparable <?> lowerEndpoint = null ;
109
117
Comparable <?> upperEndpoint = null ;
110
- BoundType lowerBoundType = null ;
111
- BoundType upperBoundType = null ;
118
+ BoundType lowerBoundType = _defaultBoundType ;
119
+ BoundType upperBoundType = _defaultBoundType ;
112
120
113
121
for (; t != JsonToken .END_OBJECT ; t = parser .nextToken ()) {
114
122
expect (parser , JsonToken .FIELD_NAME , t );
115
123
String fieldName = parser .getCurrentName ();
116
124
try {
117
125
if (fieldName .equals ("lowerEndpoint" )) {
118
- Preconditions .checkState (lowerEndpoint == null , "'lowerEndpoint' field included multiple times." );
119
126
parser .nextToken ();
120
127
lowerEndpoint = deserializeEndpoint (parser , context );
121
128
} else if (fieldName .equals ("upperEndpoint" )) {
122
- Preconditions .checkState (upperEndpoint == null , "'upperEndpoint' field included multiple times." );
123
129
parser .nextToken ();
124
130
upperEndpoint = deserializeEndpoint (parser , context );
125
131
} else if (fieldName .equals ("lowerBoundType" )) {
126
- Preconditions .checkState (lowerBoundType == null , "'lowerBoundType' field included multiple times." );
127
132
parser .nextToken ();
128
133
lowerBoundType = deserializeBoundType (parser );
129
134
} else if (fieldName .equals ("upperBoundType" )) {
130
- Preconditions .checkState (upperBoundType == null , "'upperBoundType' field included multiple times." );
131
135
parser .nextToken ();
132
136
upperBoundType = deserializeBoundType (parser );
133
137
} else {
134
138
throw context .mappingException ("Unexpected Range field: " + fieldName );
135
139
}
136
140
} catch (IllegalStateException e ) {
137
- throw new JsonMappingException ( e .getMessage ());
141
+ throw JsonMappingException . from ( parser , e .getMessage ());
138
142
}
139
143
}
140
-
141
- if (lowerBoundType == null )
142
- lowerBoundType = _defaultBoundType ;
143
-
144
- if (upperBoundType == null )
145
- upperBoundType = _defaultBoundType ;
146
-
147
144
try {
148
145
if ((lowerEndpoint != null ) && (upperEndpoint != null )) {
149
146
Preconditions .checkState (lowerEndpoint .getClass () == upperEndpoint .getClass (),
@@ -164,7 +161,7 @@ public Range<?> deserialize(JsonParser parser, DeserializationContext context)
164
161
}
165
162
return RangeFactory .all ();
166
163
} catch (IllegalStateException e ) {
167
- throw new JsonMappingException ( e .getMessage ());
164
+ throw JsonMappingException . from ( parser , e .getMessage ());
168
165
}
169
166
}
170
167
@@ -190,10 +187,10 @@ private Comparable<?> deserializeEndpoint(JsonParser parser, DeserializationCont
190
187
return (Comparable <?>) obj ;
191
188
}
192
189
193
- private void expect (JsonParser jp , JsonToken expected , JsonToken actual ) throws JsonMappingException
190
+ private void expect (JsonParser p , JsonToken expected , JsonToken actual ) throws JsonMappingException
194
191
{
195
192
if (actual != expected ) {
196
- throw new JsonMappingException ( "Expecting " + expected + ", found " + actual , jp . getCurrentLocation () );
193
+ throw JsonMappingException . from ( p , "Expecting " + expected + ", found " + actual );
197
194
}
198
195
}
199
196
}
0 commit comments