Skip to content

Commit

Permalink
Remove needless toString convert (#8092)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbumenJ committed Jun 18, 2021
1 parent b16a404 commit d16d0e1
Showing 1 changed file with 14 additions and 10 deletions.
Expand Up @@ -197,7 +197,7 @@ private static Object generalize(Object pojo, Map<Object, Object> history) {
if (history.containsKey(pojo)) {
Object pojoGeneralizedValue = history.get(pojo);
if (pojoGeneralizedValue instanceof Map
&& ((Map) pojoGeneralizedValue).containsKey(field.getName())) {
&& ((Map) pojoGeneralizedValue).containsKey(field.getName())) {
continue;
}
}
Expand Down Expand Up @@ -321,9 +321,9 @@ private static Object realize0(Object pojo, Class<?> type, Type genericType, fin
}

if (ReflectUtils.isPrimitives(pojo.getClass())
&& !(type != null && type.isArray()
&& type.getComponentType().isEnum()
&& pojo.getClass() == String[].class)) {
&& !(type != null && type.isArray()
&& type.getComponentType().isEnum()
&& pojo.getClass() == String[].class)) {
return CompatibleTypeUtils.compatibleTypeConvert(pojo, type);
}

Expand Down Expand Up @@ -412,7 +412,11 @@ private static Object realize0(Object pojo, Class<?> type, Type genericType, fin
if (type.isEnum()) {
Object name = ((Map<Object, Object>) pojo).get("name");
if (name != null) {
return Enum.valueOf((Class<Enum>) type, name.toString());
if (!(name instanceof String)) {
throw new IllegalArgumentException("`name` filed should be string!");
} else {
return Enum.valueOf((Class<Enum>) type, (String) name);
}
}
}

Expand All @@ -422,8 +426,8 @@ private static Object realize0(Object pojo, Class<?> type, Type genericType, fin
Type mapKeyType = getKeyTypeForMap(map.getClass());
Type typeKeyType = getGenericClassByIndex(genericType, 0);
boolean typeMismatch = mapKeyType instanceof Class
&& typeKeyType instanceof Class
&& !typeKeyType.getTypeName().equals(mapKeyType.getTypeName());
&& typeKeyType instanceof Class
&& !typeKeyType.getTypeName().equals(mapKeyType.getTypeName());
if (typeMismatch) {
result = createMap(new HashMap(0));
} else {
Expand Down Expand Up @@ -477,7 +481,7 @@ private static Object realize0(Object pojo, Class<?> type, Type genericType, fin
method.invoke(dest, value);
} catch (Exception e) {
String exceptionDescription = "Failed to set pojo " + dest.getClass().getSimpleName() + " property " + name
+ " value " + value + "(" + value.getClass() + "), cause: " + e.getMessage();
+ " value " + value.getClass() + ", cause: " + e.getMessage();
logger.error(exceptionDescription, e);
throw new RuntimeException(exceptionDescription, e);
}
Expand Down Expand Up @@ -658,8 +662,8 @@ private static Field getField(Class<?> cls, String fieldName) {

public static boolean isPojo(Class<?> cls) {
return !ReflectUtils.isPrimitives(cls)
&& !Collection.class.isAssignableFrom(cls)
&& !Map.class.isAssignableFrom(cls);
&& !Collection.class.isAssignableFrom(cls)
&& !Map.class.isAssignableFrom(cls);
}

/**
Expand Down

0 comments on commit d16d0e1

Please sign in to comment.