Skip to content

Commit 8c3eb03

Browse files
committed
minor future-proofing; add reportXxx() methods that will construct and throw exceptions (currently); in future possibly allow for postponing of error throwing to collect multiple problems
1 parent f40e6c1 commit 8c3eb03

File tree

1 file changed

+105
-6
lines changed

1 file changed

+105
-6
lines changed

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

Lines changed: 105 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -813,10 +813,6 @@ public <T> T readPropertyValue(JsonParser p, BeanProperty prop, JavaType type) t
813813
* @return True if there was a configured problem handler that was able to handle the
814814
* problem
815815
*/
816-
/**
817-
* Method deserializers can call to inform configured {@link DeserializationProblemHandler}s
818-
* of an unrecognized property.
819-
*/
820816
public boolean handleUnknownProperty(JsonParser p, JsonDeserializer<?> deser,
821817
Object instanceOrClass, String propName)
822818
throws IOException, JsonProcessingException
@@ -855,7 +851,109 @@ public void reportUnknownProperty(Object instanceOrClass, String fieldName,
855851
throw UnrecognizedPropertyException.from(_parser,
856852
instanceOrClass, fieldName, propIds);
857853
}
858-
854+
855+
/**
856+
* @since 2.8
857+
*/
858+
public JsonMappingException reportMappingException(String msg, Object... msgArgs)
859+
throws JsonMappingException
860+
{
861+
if (msgArgs.length > 0) {
862+
msg = String.format(msg, msgArgs);
863+
}
864+
throw mappingException(msg);
865+
}
866+
867+
/**
868+
* @since 2.8
869+
*/
870+
public JsonMappingException reportInstantiationException(Class<?> instClass, Throwable t)
871+
throws JsonMappingException
872+
{
873+
throw instantiationException(instClass, t);
874+
}
875+
876+
/**
877+
* @since 2.8
878+
*/
879+
public JsonMappingException reportInstantiationException(Class<?> instClass,
880+
String msg, Object... msgArgs)
881+
throws JsonMappingException
882+
{
883+
if (msgArgs.length > 0) {
884+
msg = String.format(msg, msgArgs);
885+
}
886+
throw instantiationException(instClass, msg);
887+
}
888+
889+
/**
890+
* @since 2.8
891+
*/
892+
public <T> T reportWeirdStringException(String value, Class<?> instClass,
893+
String msg, Object... msgArgs)
894+
throws JsonMappingException
895+
{
896+
if (msgArgs.length > 0) {
897+
msg = String.format(msg, msgArgs);
898+
}
899+
throw weirdStringException(value, instClass, msg);
900+
}
901+
902+
/**
903+
* @since 2.8
904+
*/
905+
public <T> T reportWeirdNumberException(Number value, Class<?> instClass,
906+
String msg, Object... msgArgs)
907+
throws JsonMappingException
908+
{
909+
if (msgArgs.length > 0) {
910+
msg = String.format(msg, msgArgs);
911+
}
912+
throw weirdNumberException(value, instClass, msg);
913+
}
914+
915+
/**
916+
* @since 2.8
917+
*/
918+
public <T> T reportWeirdKeyException(Class<?> keyClass, String keyValue,
919+
String msg, Object... msgArgs)
920+
throws JsonMappingException
921+
{
922+
if (msgArgs.length > 0) {
923+
msg = String.format(msg, msgArgs);
924+
}
925+
throw weirdKeyException(keyClass, keyValue, msg);
926+
}
927+
928+
/**
929+
* @since 2.8
930+
*/
931+
public <T> T reportWrongTokenException(JsonParser p,
932+
JsonToken expToken, String msg, Object... msgArgs)
933+
throws JsonMappingException
934+
{
935+
if (msgArgs.length > 0) {
936+
msg = String.format(msg, msgArgs);
937+
}
938+
throw wrongTokenException(p, expToken, msg);
939+
}
940+
941+
/**
942+
* @since 2.8
943+
*/
944+
public <T> T reportUnknownTypeException(JavaType type, String id,
945+
String extraDesc) throws JsonMappingException
946+
{
947+
throw unknownTypeException(type, id, extraDesc);
948+
}
949+
950+
/**
951+
* @since 2.8
952+
*/
953+
public <T> T reportEndOfInputException(Class<?> instClass) throws JsonMappingException {
954+
throw endOfInputException(instClass);
955+
}
956+
859957
/*
860958
/**********************************************************
861959
/* Methods for constructing exceptions
@@ -976,7 +1074,8 @@ public JsonMappingException unknownTypeException(JavaType type, String id) {
9761074
*/
9771075
public JsonMappingException unknownTypeException(JavaType type, String id,
9781076
String extraDesc) {
979-
String msg = "Could not resolve type id '"+id+"' into a subtype of "+type;
1077+
String msg = String.format("Could not resolve type id '%s' into a subtype of %s",
1078+
id, type);
9801079
if (extraDesc != null) {
9811080
msg = msg + ": "+extraDesc;
9821081
}

0 commit comments

Comments
 (0)