How can I determinate if entity and request are same type class of clazz
(Example: if(entity.equals(clazz) && request.equals(clazz)) but not work.
(In this case, i assigned ContattoCliente.class to clazz so that if is true (if (clazz == ContattoCliente.class))
Language Java version 11.
private Object convertMapMergedToEntity(Object entity, Object request, Class<?> clazz) {
List<Object> resultList = new ArrayList<>();
Object clienteMerged = new Object();
ObjectMapper mapper = JsonMapper.builder().addModule(new JavaTimeModule()).build();
if (clazz == ContattoCliente.class) {
for (int i = 0; i < ((List<Object>) request).size(); i++) {
Object contattoMerged = new Object();
LinkedHashMap<Object, Object> entityMap = mapper.convertValue(((List<Object>) entity).get(i),
LinkedHashMap.class);
LinkedHashMap<Object, Object> requestMap = mapper.convertValue(((List<Object>) request).get(i),
LinkedHashMap.class);
contattoMerged = mapDifferenceMerged2(entityMap, requestMap, clazz);
resultList.add(contattoMerged);
}
return resultList;
} else if (clazz == Cliente.class) {
LinkedHashMap<Object, Object> entityMap = mapper.convertValue(entity, LinkedHashMap.class);
LinkedHashMap<Object, Object> requestMap = mapper.convertValue(request, LinkedHashMap.class);
clienteMerged = mapDifferenceMerged2(entityMap, requestMap, clazz);
}
return clienteMerged;
}
The problem is that if i compare them with Getclass () the condition will always be false, I have also tried everything that is after Dot Getclass ()
System.out.println("entity ->" + entity.getClass());
System.out.println("request -> " + request.getClass());
System.out.println("clazz ->" + clazz.getSimpleName());
Output:
entity -> class org.hibernate.collection.internal.PersistentBag
request -> class java.util.LinkedList
clazz -> ContattoCliente