Skip to content

Commit f2b029d

Browse files
committed
minor cleanup
1 parent 76b1cdc commit f2b029d

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.fasterxml.jackson.databind.JsonMappingException;
1010
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
1111
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
12+
import com.fasterxml.jackson.databind.util.ClassUtil;
1213

1314
/**
1415
* Intermediate base deserializer class that adds more shared accessor
@@ -93,9 +94,7 @@ protected void wrapAndThrow(Throwable t, Object ref, String key) throws IOExcept
9394
throw (IOException) t;
9495
}
9596
// for [databind#1141]
96-
if (key == null) {
97-
key = "N/A";
98-
}
97+
key = ClassUtil.nonNull(key, "N/A");
9998
throw JsonMappingException.wrapWithPath(t, ref, key);
10099
}
101100
}

src/main/java/com/fasterxml/jackson/databind/util/ClassUtil.java

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,46 @@ public static <T> Constructor<T> findConstructor(Class<T> cls, boolean canFixAcc
602602
return null;
603603
}
604604

605+
/*
606+
/**********************************************************
607+
/* Class classification
608+
/**********************************************************
609+
*/
610+
611+
public static boolean isBogusClass(Class<?> cls) {
612+
return (cls == Void.class || cls == Void.TYPE
613+
|| cls == com.fasterxml.jackson.databind.annotation.NoClass.class);
614+
}
615+
616+
public static boolean isNonStaticInnerClass(Class<?> cls) {
617+
return !Modifier.isStatic(cls.getModifiers())
618+
&& (getEnclosingClass(cls) != null);
619+
}
620+
621+
/**
622+
* @since 2.7
623+
*/
624+
public static boolean isObjectOrPrimitive(Class<?> cls) {
625+
return (cls == CLS_OBJECT) || cls.isPrimitive();
626+
}
627+
628+
/**
629+
* @since 2.9
630+
*/
631+
public static <T> T nonNull(T valueOrNull, T defaultValue) {
632+
return (valueOrNull == null) ? defaultValue : valueOrNull;
633+
}
634+
635+
/**
636+
* @since 2.9
637+
*/
638+
public static String nullOrToString(Object value) {
639+
if (value == null) {
640+
return null;
641+
}
642+
return value.toString();
643+
}
644+
605645
/*
606646
/**********************************************************
607647
/* Primitive type support
@@ -889,23 +929,6 @@ public static boolean isJacksonStdImpl(Class<?> implClass) {
889929
return (implClass.getAnnotation(JacksonStdImpl.class) != null);
890930
}
891931

892-
public static boolean isBogusClass(Class<?> cls) {
893-
return (cls == Void.class || cls == Void.TYPE
894-
|| cls == com.fasterxml.jackson.databind.annotation.NoClass.class);
895-
}
896-
897-
public static boolean isNonStaticInnerClass(Class<?> cls) {
898-
return !Modifier.isStatic(cls.getModifiers())
899-
&& (getEnclosingClass(cls) != null);
900-
}
901-
902-
/**
903-
* @since 2.7
904-
*/
905-
public static boolean isObjectOrPrimitive(Class<?> cls) {
906-
return (cls == CLS_OBJECT) || cls.isPrimitive();
907-
}
908-
909932
/*
910933
/**********************************************************
911934
/* Access to various Class definition aspects; possibly

src/main/java/com/fasterxml/jackson/databind/util/TokenBuffer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,16 +1423,15 @@ public String getText()
14231423
if (ob instanceof String) {
14241424
return (String) ob;
14251425
}
1426-
return (ob == null) ? null : ob.toString();
1426+
return ClassUtil.nullOrToString(ob);
14271427
}
14281428
if (_currToken == null) {
14291429
return null;
14301430
}
14311431
switch (_currToken) {
14321432
case VALUE_NUMBER_INT:
14331433
case VALUE_NUMBER_FLOAT:
1434-
Object ob = _currentObject();
1435-
return (ob == null) ? null : ob.toString();
1434+
return ClassUtil.nullOrToString(_currentObject());
14361435
default:
14371436
return _currToken.asString();
14381437
}

0 commit comments

Comments
 (0)