aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-common-lib
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-common-lib')
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java
index 18750e4d0a..206eae3491 100644
--- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java
@@ -37,6 +37,7 @@ import org.openecomp.sdc.common.errors.Messages;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@@ -176,11 +177,34 @@ public class CommonUtil {
Map<String, Object> objectAsMap = getObjectAsMap(objectCandidate);
T result = classToCreate.newInstance();
+
+ Field[] declaredFields = classToCreate.getDeclaredFields();
+ for( Field field : declaredFields){
+ if(isComplexClass(field)){
+ Optional<?> objectUsingSetters =
+ createObjectUsingSetters(objectAsMap.get(field.getName()), field.getType());
+ if( objectUsingSetters.isPresent()){
+ objectAsMap.remove(field.getName());
+ objectAsMap.put(field.getName(), objectUsingSetters.get());
+ }
+ }
+ }
BeanUtils.populate(result, objectAsMap);
return Optional.of(result);
}
+ private static boolean isComplexClass(Field field) {
+ return !field.getType().equals(Map.class)
+ && !field.getType().equals(String.class)
+ && !field.getType().equals(Integer.class)
+ && !field.getType().equals(Float.class)
+ && !field.getType().equals(Double.class)
+ && !field.getType().equals(Set.class)
+ && !field.getType().equals(Object.class)
+ && !field.getType().equals(List.class);
+ }
+
public static Map<String, Object> getObjectAsMap(Object obj) {
Map<String, Object> objectAsMap = obj instanceof Map ? (Map<String, Object>) obj
: new ObjectMapper().convertValue(obj, Map.class);