ResourceEntry
This commit is contained in:
@@ -19,10 +19,10 @@ import org.redkale.annotation.*;
|
|||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
import org.redkale.inject.spi.ResourceAnnotationProvider;
|
import org.redkale.inject.spi.ResourceAnnotationProvider;
|
||||||
import org.redkale.util.Creator;
|
|
||||||
import org.redkale.util.RedkaleClassLoader;
|
import org.redkale.util.RedkaleClassLoader;
|
||||||
import org.redkale.util.RedkaleException;
|
import org.redkale.util.RedkaleException;
|
||||||
import org.redkale.util.TypeToken;
|
import org.redkale.util.TypeToken;
|
||||||
|
import org.redkale.util.Utility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -1036,31 +1036,8 @@ public final class ResourceFactory {
|
|||||||
if (rs == null && defval != null) {
|
if (rs == null && defval != null) {
|
||||||
rs = gencType == String.class ? defval : JsonConvert.root().convertFrom(gencType, defval);
|
rs = gencType == String.class ? defval : JsonConvert.root().convertFrom(gencType, defval);
|
||||||
}
|
}
|
||||||
if (rs != null && !rs.getClass().isPrimitive() && (classType.isPrimitive()
|
if (rs != null && !Objects.equals(rs.getClass(), classType)) {
|
||||||
|| classType == Integer.class
|
rs = Utility.convertValue(gencType, rs);
|
||||||
|| classType == Long.class || classType == Short.class
|
|
||||||
|| classType == Boolean.class || classType == Byte.class
|
|
||||||
|| classType == Float.class || classType == Double.class
|
|
||||||
|| classType == BigInteger.class || classType == BigDecimal.class)) {
|
|
||||||
if (classType == int.class || classType == Integer.class) {
|
|
||||||
rs = Integer.decode(rs.toString());
|
|
||||||
} else if (classType == long.class || classType == Long.class) {
|
|
||||||
rs = Long.decode(rs.toString());
|
|
||||||
} else if (classType == short.class || classType == Short.class) {
|
|
||||||
rs = Short.decode(rs.toString());
|
|
||||||
} else if (classType == boolean.class || classType == Boolean.class) {
|
|
||||||
rs = "true".equalsIgnoreCase(rs.toString());
|
|
||||||
} else if (classType == byte.class || classType == Byte.class) {
|
|
||||||
rs = Byte.decode(rs.toString());
|
|
||||||
} else if (classType == float.class || classType == Float.class) {
|
|
||||||
rs = Float.parseFloat(rs.toString());
|
|
||||||
} else if (classType == double.class || classType == Double.class) {
|
|
||||||
rs = Double.parseDouble(rs.toString());
|
|
||||||
} else if (classType == BigInteger.class) {
|
|
||||||
rs = new BigInteger(rs.toString());
|
|
||||||
} else if (classType == BigDecimal.class) {
|
|
||||||
rs = new BigDecimal(rs.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (rs != null) {
|
if (rs != null) {
|
||||||
field.set(srcObj, rs);
|
field.set(srcObj, rs);
|
||||||
@@ -1202,38 +1179,13 @@ public final class ResourceFactory {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.elements = elements == null ? new CopyOnWriteArrayList<>() : elements;
|
this.elements = elements == null ? new CopyOnWriteArrayList<>() : elements;
|
||||||
if (sync && elements != null && !elements.isEmpty()) {
|
if (sync && Utility.isNotEmpty(elements)) {
|
||||||
for (ResourceElement element : elements) {
|
for (ResourceElement element : elements) {
|
||||||
Object dest = element.dest.get();
|
Object dest = element.dest.get();
|
||||||
if (dest == null) {
|
if (dest == null) {
|
||||||
continue; //依赖对象可能被销毁了
|
continue; //依赖对象可能被销毁了
|
||||||
}
|
}
|
||||||
Object newVal = value;
|
Object newVal = Utility.convertValue(element.fieldType, value);
|
||||||
final Class classType = element.fieldType;
|
|
||||||
if (newVal != null && !newVal.getClass().isPrimitive() && (classType.isPrimitive() || Number.class.isAssignableFrom(classType))) {
|
|
||||||
if (classType == int.class || classType == Integer.class) {
|
|
||||||
newVal = Integer.decode(newVal.toString());
|
|
||||||
} else if (classType == long.class || classType == Long.class) {
|
|
||||||
newVal = Long.decode(newVal.toString());
|
|
||||||
} else if (classType == short.class || classType == Short.class) {
|
|
||||||
newVal = Short.decode(newVal.toString());
|
|
||||||
} else if (classType == boolean.class || classType == Boolean.class) {
|
|
||||||
newVal = "true".equalsIgnoreCase(newVal.toString());
|
|
||||||
} else if (classType == byte.class || classType == Byte.class) {
|
|
||||||
newVal = Byte.decode(newVal.toString());
|
|
||||||
} else if (classType == float.class || classType == Float.class) {
|
|
||||||
newVal = Float.parseFloat(newVal.toString());
|
|
||||||
} else if (classType == double.class || classType == Double.class) {
|
|
||||||
newVal = Double.parseDouble(newVal.toString());
|
|
||||||
} else if (classType == BigInteger.class) {
|
|
||||||
newVal = new BigInteger(newVal.toString());
|
|
||||||
} else if (classType == BigDecimal.class) {
|
|
||||||
newVal = new BigDecimal(newVal.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (newVal == null && classType.isPrimitive()) {
|
|
||||||
newVal = Array.get(Creator.newArray(classType, 1), 0);
|
|
||||||
}
|
|
||||||
Object oldVal = null;
|
Object oldVal = null;
|
||||||
if (element.changedMethod != null) {
|
if (element.changedMethod != null) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ import java.util.stream.Stream;
|
|||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
import javax.crypto.*;
|
import javax.crypto.*;
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
|
||||||
import org.redkale.annotation.ClassDepends;
|
import org.redkale.annotation.ClassDepends;
|
||||||
|
import org.redkale.convert.json.JsonConvert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -3443,10 +3443,31 @@ public final class Utility {
|
|||||||
*/
|
*/
|
||||||
@ClassDepends(Copier.class)
|
@ClassDepends(Copier.class)
|
||||||
public static <T> T convertValue(Type type, Object value) {
|
public static <T> T convertValue(Type type, Object value) {
|
||||||
if (type == null || value == null) {
|
if (type == null) {
|
||||||
return (T) value;
|
return (T) value;
|
||||||
}
|
}
|
||||||
final Class typeClazz = TypeToken.typeToClass(type);
|
final Class typeClazz = TypeToken.typeToClass(type);
|
||||||
|
if (value == null) {
|
||||||
|
if (typeClazz == boolean.class) {
|
||||||
|
return (T) Boolean.FALSE;
|
||||||
|
} else if (typeClazz == byte.class) {
|
||||||
|
return (T) (Byte) (byte) 0;
|
||||||
|
} else if (typeClazz == char.class) {
|
||||||
|
return (T) (Character) (char) 0;
|
||||||
|
} else if (typeClazz == short.class) {
|
||||||
|
return (T) (Short) (short) 0;
|
||||||
|
} else if (typeClazz == int.class) {
|
||||||
|
return (T) (Integer) 0;
|
||||||
|
} else if (typeClazz == long.class) {
|
||||||
|
return (T) (Long) 0L;
|
||||||
|
} else if (typeClazz == float.class) {
|
||||||
|
return (T) (Float) 0F;
|
||||||
|
} else if (typeClazz == double.class) {
|
||||||
|
return (T) (Double) 0D;
|
||||||
|
}
|
||||||
|
return (T) value;
|
||||||
|
}
|
||||||
|
|
||||||
final Class valClazz = value.getClass();
|
final Class valClazz = value.getClass();
|
||||||
if (typeClazz == valClazz || typeClazz.isAssignableFrom(valClazz)) {
|
if (typeClazz == valClazz || typeClazz.isAssignableFrom(valClazz)) {
|
||||||
return (T) value;
|
return (T) value;
|
||||||
|
|||||||
Reference in New Issue
Block a user