Skip to content

Commit

Permalink
Refactoring to use formatting variant of method
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jul 9, 2015
1 parent 5dfc92c commit 46a9900
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 68 deletions.
Expand Up @@ -539,8 +539,8 @@ protected void addBeanProps(DeserializationContext ctxt,
}
}
if (cprop == null) {
throw ctxt.mappingException("Could not find creator property with name '"
+name+"' (in class "+beanDesc.getBeanClass().getName()+")");
throw ctxt.mappingException("Could not find creator property with name '%s' (in class %s)",
name, beanDesc.getBeanClass().getName());
}
if (prop != null) {
cprop.setFallbackSetter(prop);
Expand Down
Expand Up @@ -143,8 +143,8 @@ public boolean canInstantiate() {
* null or empty List.
*/
public Object createUsingDefault(DeserializationContext ctxt) throws IOException {
throw ctxt.mappingException("Can not instantiate value of type "
+getValueTypeDesc()+"; no default creator found");
throw ctxt.mappingException("Can not instantiate value of type %s; no default creator found",
getValueTypeDesc());
}

/**
Expand All @@ -156,17 +156,19 @@ public Object createUsingDefault(DeserializationContext ctxt) throws IOException
* a non-empty List of arguments.
*/
public Object createFromObjectWith(DeserializationContext ctxt, Object[] args) throws IOException {
throw ctxt.mappingException("Can not instantiate value of type "+getValueTypeDesc()+" with arguments");
throw ctxt.mappingException("Can not instantiate value of type %s with arguments",
getValueTypeDesc());
}

/**
* Method to called to create value instance from JSON Object using
* an intermediate "delegate" value to pass to createor method
*/
public Object createUsingDelegate(DeserializationContext ctxt, Object delegate) throws IOException {
throw ctxt.mappingException("Can not instantiate value of type "+getValueTypeDesc()+" using delegate");
throw ctxt.mappingException("Can not instantiate value of type %s using delegate",
getValueTypeDesc());
}

/*
/**********************************************************
/* Instantiation methods for JSON scalar types
Expand All @@ -179,23 +181,23 @@ public Object createFromString(DeserializationContext ctxt, String value) throws
}

public Object createFromInt(DeserializationContext ctxt, int value) throws IOException {
throw ctxt.mappingException("Can not instantiate value of type "
+getValueTypeDesc()+" from Integer number ("+value+", int)");
throw ctxt.mappingException("Can not instantiate value of type %s from Integer number (%s, int)",
getValueTypeDesc(), value);
}

public Object createFromLong(DeserializationContext ctxt, long value) throws IOException {
throw ctxt.mappingException("Can not instantiate value of type "
+getValueTypeDesc()+" from Integer number ("+value+", long)");
throw ctxt.mappingException("Can not instantiate value of type %s from Integer number (%s, long)",
getValueTypeDesc(), value);
}

public Object createFromDouble(DeserializationContext ctxt, double value) throws IOException {
throw ctxt.mappingException("Can not instantiate value of type "
+getValueTypeDesc()+" from Floating-point number ("+value+", double)");
throw ctxt.mappingException("Can not instantiate value of type %s from Floating-point number (%s, double)",
getValueTypeDesc(), value);
}

public Object createFromBoolean(DeserializationContext ctxt, boolean value) throws IOException {
throw ctxt.mappingException("Can not instantiate value of type "
+getValueTypeDesc()+" from Boolean value ("+value+")");
throw ctxt.mappingException("Can not instantiate value of type %s from Boolean value (%s)",
getValueTypeDesc(), value);
}

/*
Expand Down Expand Up @@ -274,7 +276,7 @@ protected Object _createFromStringFallbacks(DeserializationContext ctxt, String
return null;
}
}
throw ctxt.mappingException("Can not instantiate value of type "+getValueTypeDesc()
+" from String value ('"+value+"'); no single-String constructor/factory method");
throw ctxt.mappingException("Can not instantiate value of type %s from String value ('%s'); no single-String constructor/factory method",
getValueTypeDesc(), value);
}
}
Expand Up @@ -128,7 +128,8 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt)
}
// Ok; extra fields? Let's fail, unless ignoring extra props is fine
if (!_ignoreAllUnknown) {
throw ctxt.mappingException("Unexpected JSON values; expected at most "+propCount+" properties (in JSON Array)");
throw ctxt.mappingException("Unexpected JSON values; expected at most %d properties (in JSON Array)",
propCount);
}
// otherwise, skip until end
while (p.nextToken() != JsonToken.END_ARRAY) {
Expand Down Expand Up @@ -172,7 +173,8 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt, Object buil

// Ok; extra fields? Let's fail, unless ignoring extra props is fine
if (!_ignoreAllUnknown) {
throw ctxt.mappingException("Unexpected JSON values; expected at most "+propCount+" properties (in JSON Array)");
throw ctxt.mappingException("Unexpected JSON values; expected at most %d properties (in JSON Array)",
propCount);
}
// otherwise, skip until end
while (p.nextToken() != JsonToken.END_ARRAY) {
Expand Down Expand Up @@ -239,7 +241,8 @@ protected Object _deserializeNonVanilla(JsonParser p, DeserializationContext ctx
}
// Ok; extra fields? Let's fail, unless ignoring extra props is fine
if (!_ignoreAllUnknown) {
throw ctxt.mappingException("Unexpected JSON values; expected at most "+propCount+" properties (in JSON Array)");
throw ctxt.mappingException("Unexpected JSON values; expected at most %d properties (in JSON Array)",
propCount);
}
// otherwise, skip until end
while (p.nextToken() != JsonToken.END_ARRAY) {
Expand Down Expand Up @@ -322,7 +325,8 @@ protected final Object _deserializeUsingPropertyBased(final JsonParser p,
* but make explicitly non-supported for now.
*/
throw ctxt.mappingException("Can not support implicit polymorphic deserialization for POJOs-as-Arrays style: "
+"nominal type "+_beanType.getRawClass().getName()+", actual type "+builder.getClass().getName());
+"nominal type %s, actual type %s",
_beanType.getRawClass().getName(), builder.getClass().getName());
}
}
continue;
Expand Down Expand Up @@ -353,14 +357,15 @@ protected final Object _deserializeUsingPropertyBased(final JsonParser p,
/**********************************************************
*/

protected Object _deserializeFromNonArray(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
protected Object _deserializeFromNonArray(JsonParser p, DeserializationContext ctxt)
throws IOException
{
// Let's start with failure
throw ctxt.mappingException("Can not deserialize a POJO (of type "+_beanType.getRawClass().getName()
+") from non-Array representation (token: "+jp.getCurrentToken()
+"): type/property designed to be serialized as JSON Array");
throw ctxt.mappingException("Can not deserialize a POJO (of type %s) from non-Array representation (token: %s): "
+"type/property designed to be serialized as JSON Array",
_beanType.getRawClass().getName(),
p.getCurrentToken());
// in future, may allow use of "standard" POJO serialization as well; if so, do:
//return _delegate.deserialize(jp, ctxt);
//return _delegate.deserialize(p, ctxt);
}
}
Expand Up @@ -122,7 +122,8 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt)
}
// Ok; extra fields? Let's fail, unless ignoring extra props is fine
if (!_ignoreAllUnknown) {
throw ctxt.mappingException("Unexpected JSON values; expected at most "+propCount+" properties (in JSON Array)");
throw ctxt.mappingException("Unexpected JSON values; expected at most %d properties (in JSON Array)",
propCount);
}
// otherwise, skip until end
while (p.nextToken() != JsonToken.END_ARRAY) {
Expand Down Expand Up @@ -168,7 +169,8 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt, Object bean

// Ok; extra fields? Let's fail, unless ignoring extra props is fine
if (!_ignoreAllUnknown) {
throw ctxt.mappingException("Unexpected JSON values; expected at most "+propCount+" properties (in JSON Array)");
throw ctxt.mappingException("Unexpected JSON values; expected at most %d properties (in JSON Array)",
propCount);
}
// otherwise, skip until end
while (p.nextToken() != JsonToken.END_ARRAY) {
Expand Down Expand Up @@ -236,7 +238,8 @@ protected Object _deserializeNonVanilla(JsonParser p, DeserializationContext ctx
}
// Ok; extra fields? Let's fail, unless ignoring extra props is fine
if (!_ignoreAllUnknown) {
throw ctxt.mappingException("Unexpected JSON values; expected at most "+propCount+" properties (in JSON Array)");
throw ctxt.mappingException("Unexpected JSON values; expected at most %d properties (in JSON Array)",
propCount);
}
// otherwise, skip until end
while (p.nextToken() != JsonToken.END_ARRAY) {
Expand Down Expand Up @@ -320,7 +323,8 @@ protected final Object _deserializeUsingPropertyBased(final JsonParser p, final
* but make explicitly non-supported for now.
*/
throw ctxt.mappingException("Can not support implicit polymorphic deserialization for POJOs-as-Arrays style: "
+"nominal type "+_beanType.getRawClass().getName()+", actual type "+bean.getClass().getName());
+"nominal type %s, actual type %s",
_beanType.getRawClass().getName(), bean.getClass().getName());
}
}
continue;
Expand Down Expand Up @@ -355,10 +359,11 @@ protected Object _deserializeFromNonArray(JsonParser p, DeserializationContext c
throws IOException
{
// Let's start with failure
throw ctxt.mappingException("Can not deserialize a POJO (of type "+_beanType.getRawClass().getName()
+") from non-Array representation (token: "+p.getCurrentToken()
+"): type/property designed to be serialized as JSON Array");
throw ctxt.mappingException("Can not deserialize a POJO (of type %s) from non-Array representation (token: %s): "
+"type/property designed to be serialized as JSON Array",
_beanType.getRawClass().getName(),
p.getCurrentToken());
// in future, may allow use of "standard" POJO serialization as well; if so, do:
//return _delegate.deserialize(jp, ctxt);
//return _delegate.deserialize(p, ctxt);
}
}
Expand Up @@ -150,13 +150,15 @@ public Object complete(JsonParser jp, DeserializationContext ctxt, Object bean)
}
// 26-Oct-2012, tatu: As per [Issue#94], must allow use of 'defaultImpl'
if (!_properties[i].hasDefaultType()) {
throw ctxt.mappingException("Missing external type id property '"+_properties[i].getTypePropertyName()+"'");
throw ctxt.mappingException("Missing external type id property '%s'",
_properties[i].getTypePropertyName());
}
typeId = _properties[i].getDefaultTypeId();
}
} else if (_tokens[i] == null) {
SettableBeanProperty prop = _properties[i].getProperty();
throw ctxt.mappingException("Missing property '"+prop.getName()+"' for external type id '"+_properties[i].getTypePropertyName());
throw ctxt.mappingException("Missing property '%s' for external type id '%s'",
prop.getName(), _properties[i].getTypePropertyName());
}
_deserializeAndSet(jp, ctxt, bean, i, typeId);
}
Expand Down Expand Up @@ -184,12 +186,14 @@ public Object complete(JsonParser jp, DeserializationContext ctxt,
// but not just one
// 26-Oct-2012, tatu: As per [Issue#94], must allow use of 'defaultImpl'
if (!_properties[i].hasDefaultType()) {
throw ctxt.mappingException("Missing external type id property '"+_properties[i].getTypePropertyName()+"'");
throw ctxt.mappingException("Missing external type id property '%s'",
_properties[i].getTypePropertyName());
}
typeId = _properties[i].getDefaultTypeId();
} else if (_tokens[i] == null) {
SettableBeanProperty prop = _properties[i].getProperty();
throw ctxt.mappingException("Missing property '"+prop.getName()+"' for external type id '"+_properties[i].getTypePropertyName());
throw ctxt.mappingException("Missing property '%s' for external type id '%s'",
prop.getName(), _properties[i].getTypePropertyName());
}
values[i] = _deserialize(jp, ctxt, i, typeId);
}
Expand Down
Expand Up @@ -30,8 +30,9 @@ public NullProvider(JavaType type, Object nullValue)
public Object nullValue(DeserializationContext ctxt) throws JsonProcessingException
{
if (_isPrimitive && ctxt.isEnabled(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)) {
throw ctxt.mappingException("Can not map JSON null into type "+_rawType.getName()
+" (set DeserializationConfig.DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES to 'false' to allow)");
throw ctxt.mappingException("Can not map JSON null into type %s"
+" (set DeserializationConfig.DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES to 'false' to allow)",
_rawType.getName());
}
return _nullValue;
}
Expand Down
Expand Up @@ -138,12 +138,12 @@ protected Object _findMissing(SettableBeanProperty prop) throws JsonMappingExcep
}
// Second: required?
if (prop.isRequired()) {
throw _context.mappingException(String.format("Missing required creator property '%s' (index %d)",
prop.getName(), prop.getCreatorIndex()));
throw _context.mappingException("Missing required creator property '%s' (index %d)",
prop.getName(), prop.getCreatorIndex());
}
if (_context.isEnabled(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES)) {
throw _context.mappingException(String.format("Missing creator property '%s' (index %d); DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES enabled",
prop.getName(), prop.getCreatorIndex()));
throw _context.mappingException("Missing creator property '%s' (index %d); DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES enabled",
prop.getName(), prop.getCreatorIndex());
}
// Third: default value
JsonDeserializer<Object> deser = prop.getValueDeserializer();
Expand Down Expand Up @@ -188,8 +188,8 @@ public Object handleIdValue(final DeserializationContext ctxt, Object bean) thro
}
} else {
// TODO: is this an error case?
throw ctxt.mappingException("No _idValue when handleIdValue called, on instance of "
+bean.getClass().getName());
throw ctxt.mappingException("No _idValue when handleIdValue called, on instance of %s",
bean.getClass().getName());
}
}
return bean;
Expand Down
Expand Up @@ -158,7 +158,8 @@ public T deserialize(JsonParser jp, DeserializationContext ctxt) throws IOExcept

protected T _deserializeEmbedded(Object ob, DeserializationContext ctxt) throws IOException {
// default impl: error out
throw ctxt.mappingException("Don't know how to convert embedded Object of type "+ob.getClass().getName()+" into "+_valueClass.getName());
throw ctxt.mappingException("Don't know how to convert embedded Object of type %s into %s",
ob.getClass().getName(), _valueClass.getName());
}

protected T _deserializeFromEmptyString() throws IOException {
Expand Down
Expand Up @@ -138,10 +138,9 @@ protected PrimitiveOrWrapperDeserializer(Class<T> vc, T nvl) {
public final T getNullValue(DeserializationContext ctxt) throws JsonMappingException
{
if (_primitive && ctxt.isEnabled(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)) {
String msg = String.format(
throw ctxt.mappingException(
"Can not map JSON null into type %s (set DeserializationConfig.DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES to 'false' to allow)",
handledType().toString());
throw ctxt.mappingException(msg);
}
return _nullValue;
}
Expand Down
Expand Up @@ -1053,8 +1053,7 @@ protected void handleUnknownProperty(JsonParser jp, DeserializationContext ctxt,
protected void _failDoubleToIntCoercion(JsonParser jp, DeserializationContext ctxt,
String type) throws IOException
{
throw ctxt.mappingException(String.format
("Can not coerce a floating-point value ('%s') into %s; enable `DeserializationFeature.ACCEPT_FLOAT_AS_INT` to allow",
jp.getValueAsString(), type));
throw ctxt.mappingException("Can not coerce a floating-point value ('%s') into %s; enable `DeserializationFeature.ACCEPT_FLOAT_AS_INT` to allow",
jp.getValueAsString(), type);
}
}

0 comments on commit 46a9900

Please sign in to comment.