Skip to content

Commit 98dd091

Browse files
committed
minor refactoring related to exception handling
1 parent 0b6cb9b commit 98dd091

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/main/java/com/fasterxml/jackson/databind/DeserializationContext.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,25 @@ public JsonMappingException mappingException(String msgTemplate, Object... args)
11331133
/**********************************************************
11341134
*/
11351135

1136+
/**
1137+
* Helper method for constructing {@link JsonMappingException} to indicated
1138+
* that the token encountered was of type different than what <b>should</b>
1139+
* be seen at that position, usually within a sequence of expected tokens.
1140+
* Note that most of the time this method should NOT be directly called;
1141+
* instead, {@link #reportWrongTokenException} should be called and will
1142+
* call this method as necessary.
1143+
*/
1144+
public JsonMappingException wrongTokenException(JsonParser p, JsonToken expToken,
1145+
String msg0)
1146+
{
1147+
String msg = String.format("Unexpected token (%s), expected %s",
1148+
p.getCurrentToken(), expToken);
1149+
if (msg0 != null) {
1150+
msg = msg + ": "+msg0;
1151+
}
1152+
return JsonMappingException.from(p, msg);
1153+
}
1154+
11361155
/**
11371156
* Helper method for constructing exception to indicate that given JSON
11381157
* Object field name was not in format to be able to deserialize specified
@@ -1234,22 +1253,6 @@ public JsonMappingException instantiationException(Class<?> instClass, String ms
12341253
instClass.getName(), msg));
12351254
}
12361255

1237-
/**
1238-
* Helper method for indicating that the current token was expected to be another
1239-
* token.
1240-
*
1241-
* @deprecated Since 2.8 use {@link #reportWrongTokenException} instead
1242-
*/
1243-
@Deprecated
1244-
public JsonMappingException wrongTokenException(JsonParser p, JsonToken expToken, String msg0) {
1245-
String msg = String.format("Unexpected token (%s), expected %s",
1246-
p.getCurrentToken(), expToken);
1247-
if (msg0 != null) {
1248-
msg = msg + ": "+msg0;
1249-
}
1250-
return JsonMappingException.from(p, msg);
1251-
}
1252-
12531256
/**
12541257
* @since 2.5
12551258
*

src/main/java/com/fasterxml/jackson/databind/jsontype/impl/AsArrayTypeDeserializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ protected String _locateTypeId(JsonParser p, DeserializationContext ctxt) throws
131131
if (_defaultImpl != null) {
132132
return _idResolver.idFromBaseType();
133133
}
134-
ctxt.reportWrongTokenException(p, JsonToken.START_ARRAY, "need JSON Array to contain As.WRAPPER_ARRAY type information for class "+baseTypeName());
134+
ctxt.reportWrongTokenException(p, JsonToken.START_ARRAY,
135+
"need JSON Array to contain As.WRAPPER_ARRAY type information for class "+baseTypeName());
135136
return null;
136137
}
137138
// And then type id as a String

0 commit comments

Comments
 (0)