Skip to content

Commit 2d318f6

Browse files
committed
Try to straight out eof handling; for now there's no way to really catch that at databind
1 parent dbd854d commit 2d318f6

File tree

4 files changed

+28
-25
lines changed

4 files changed

+28
-25
lines changed

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ public Object handleWeirdKey(Class<?> keyClass, String keyValue,
867867
while (h != null) {
868868
// Can bail out if it's handled
869869
Object key = h.value().handleWeirdKey(this, keyClass, keyValue, msg);
870-
if (key != DeserializationProblemHandler.NOT_HANDLED) {
870+
if (key != DeserializationProblemHandler.NOT_HANDLED) {
871871
return key;
872872
}
873873
h = h.next();
@@ -993,13 +993,6 @@ public JsonMappingException reportWrongTokenException(JsonParser p,
993993
throw wrongTokenException(p, expToken, msg);
994994
}
995995

996-
/**
997-
* @since 2.8
998-
*/
999-
public void reportEndOfInputException(Class<?> instClass) throws JsonMappingException {
1000-
throw endOfInputException(instClass);
1001-
}
1002-
1003996
/**
1004997
* @since 2.8
1005998
*/
@@ -1076,6 +1069,13 @@ public JsonMappingException mappingException(String msgTemplate, Object... args)
10761069
return JsonMappingException.from(getParser(), msgTemplate);
10771070
}
10781071

1072+
/*
1073+
/**********************************************************
1074+
/* Methods for constructing semantic exceptions; usually not
1075+
/* to be called direclty, call `handleXxx()` instead
1076+
/**********************************************************
1077+
*/
1078+
10791079
/**
10801080
* Helper method for constructing exception to indicate that given JSON
10811081
* Object field name was not in format to be able to deserialize specified
@@ -1089,6 +1089,18 @@ public JsonMappingException weirdKeyException(Class<?> keyClass, String keyValue
10891089
keyValue, keyClass);
10901090
}
10911091

1092+
/**
1093+
* Helper method for constructing exception to indicate that end-of-input was
1094+
* reached while still expecting more tokens to deserialize value of specified type.
1095+
*
1096+
* @deprecated Since 2.8; currently no way to catch EOF at databind level
1097+
*/
1098+
@Deprecated
1099+
public JsonMappingException endOfInputException(Class<?> instClass) {
1100+
return JsonMappingException.from(_parser, "Unexpected end-of-input when trying to deserialize a "
1101+
+instClass.getName());
1102+
}
1103+
10921104
/*
10931105
/**********************************************************
10941106
/* Methods for constructing semantic exceptions; mostly
@@ -1188,15 +1200,6 @@ public JsonMappingException unknownTypeException(JavaType type, String id,
11881200
return JsonMappingException.from(_parser, msg);
11891201
}
11901202

1191-
/**
1192-
* @deprecated Since 2.8 use {@link #reportEndOfInputException} instead
1193-
*/
1194-
@Deprecated
1195-
public JsonMappingException endOfInputException(Class<?> instClass) {
1196-
return JsonMappingException.from(_parser, "Unexpected end-of-input when trying to deserialize a "
1197-
+instClass.getName());
1198-
}
1199-
12001203
/*
12011204
/**********************************************************
12021205
/* Overridable internal methods

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ protected final Object _deserializeOther(JsonParser p, DeserializationContext ct
172172
return null;
173173
}
174174

175+
@Deprecated // since 2.8; remove unless getting used
175176
protected Object _missingToken(JsonParser p, DeserializationContext ctxt) throws IOException {
176-
ctxt.reportEndOfInputException(handledType());
177-
return null;
177+
throw ctxt.endOfInputException(handledType());
178178
}
179179

180180
/**

src/main/java/com/fasterxml/jackson/databind/deser/std/JsonNodeDeserializer.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,6 @@ protected final ArrayNode deserializeArray(JsonParser p, DeserializationContext
265265
ArrayNode node = nodeFactory.arrayNode();
266266
while (true) {
267267
JsonToken t = p.nextToken();
268-
if (t == null) {
269-
ctxt.reportEndOfInputException(ArrayNode.class);
270-
return node;
271-
}
272268
switch (t.id()) {
273269
case JsonTokenId.ID_START_OBJECT:
274270
node.add(deserializeObject(p, ctxt, nodeFactory));
@@ -378,7 +374,6 @@ protected final JsonNode _fromFloat(JsonParser p, DeserializationContext ctxt,
378374
protected final JsonNode _fromEmbedded(JsonParser p, DeserializationContext ctxt,
379375
JsonNodeFactory nodeFactory) throws IOException
380376
{
381-
// [JACKSON-796]
382377
Object ob = p.getEmbeddedObject();
383378
if (ob == null) { // should this occur?
384379
return nodeFactory.nullNode();

src/test/java/com/fasterxml/jackson/databind/filter/ProblemHandlerTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
import com.fasterxml.jackson.databind.*;
88
import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
99

10+
/**
11+
* Tests to exercise handler methods of {@link DeserializationProblemHandler}.
12+
*
13+
* @since 2.8
14+
*/
1015
public class ProblemHandlerTest extends BaseMapTest
1116
{
1217
static class WeirdKeyHandler
@@ -54,7 +59,7 @@ static class Impl extends Base {
5459
static class BaseWrapper {
5560
public Base value;
5661
}
57-
62+
5863
/*
5964
/**********************************************************
6065
/* Test methods

0 commit comments

Comments
 (0)