|
|
@@ -3,6 +3,7 @@ package com.usai.redant.apexdrivers.base;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
+import java.lang.reflect.InvocationTargetException;
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
|
public class BasicObject {
|
|
|
@@ -33,45 +34,38 @@ public class BasicObject {
|
|
|
if (type == value.getClass() || ((type == int.class || type == long.class) && value.getClass() == Integer.class) || ((type == float.class || type == double.class) && (value.getClass() == Double.class || value.getClass() == Float.class))) {
|
|
|
|
|
|
|
|
|
- String setter = "set" + toUpperCaseFirstOne(key);
|
|
|
- try {
|
|
|
- Method method = cls.getMethod(setter,type);
|
|
|
- if (method != null) {
|
|
|
- method.invoke(this,value);
|
|
|
- } else {
|
|
|
- f.set(this,value);
|
|
|
- }
|
|
|
- } catch (NoSuchMethodException e) {
|
|
|
-
|
|
|
- e.printStackTrace();
|
|
|
-
|
|
|
- f.set(this,value);
|
|
|
- } catch (SecurityException e) {
|
|
|
- e.printStackTrace();
|
|
|
-
|
|
|
- f.set(this,value);
|
|
|
- }
|
|
|
+ boolean success = invokeSetter(cls,f,type,key,value);
|
|
|
+ if (!success) {
|
|
|
+ f.set(this,value);
|
|
|
+ }
|
|
|
|
|
|
} else {
|
|
|
+
|
|
|
if (value.getClass() == String.class) {
|
|
|
+
|
|
|
String string = (String)value;
|
|
|
- if (type == Integer.class) {
|
|
|
+
|
|
|
+ if (type == Integer.class || type == int.class || type == long.class) {
|
|
|
|
|
|
value = Integer.valueOf(string);
|
|
|
- f.set(this,value);
|
|
|
|
|
|
- } else if (type == Double.class) {
|
|
|
+
|
|
|
+ } else if (type == Double.class || type == double.class || type == float.class) {
|
|
|
|
|
|
value = Double.valueOf(string);
|
|
|
- f.set(this,value);
|
|
|
|
|
|
- } else if (type == Boolean.class) {
|
|
|
+ } else if (type == Boolean.class || type == boolean.class) {
|
|
|
|
|
|
value = Boolean.valueOf(string);
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean success = invokeSetter(cls,f,type,key,value);
|
|
|
+ if (!success) {
|
|
|
f.set(this,value);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -82,6 +76,26 @@ public class BasicObject {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public boolean invokeSetter(Class cls, Field f, Class type,String key,Object value) {
|
|
|
+
|
|
|
+ String setter = "set" + toUpperCaseFirstOne(key);
|
|
|
+ try {
|
|
|
+ Method method = cls.getMethod(setter,type);
|
|
|
+ if (method != null) {
|
|
|
+
|
|
|
+ method.invoke(this,value);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
public static String toUpperCaseFirstOne(String s){
|
|
|
if(Character.isUpperCase(s.charAt(0)))
|
|
|
return s;
|