/** * Create builder or target object if needed and call * {@link MappingProcessor#mapToDestObject(org.dozer.classmap.ClassMap, Object, Object, boolean, String)} function with * arguments {@code classMap}, {@code srcObj}, {@code result}, {@code bypassSuperMappings}, {@code mapId} * @param creationDirective directive for concrete mapping (based mostly on {@code classMap}) * @param classMap class map information for concrete class * @param srcObj source object * @param result target entity for mapping * @param bypassSuperMappings //TODO * @param mapId mapping identifier * @return result or created target entity for mapping */ private <T> T createByCreationDirectiveAndMap(BeanCreationDirective creationDirective, ClassMap classMap, Object srcObj, T result, boolean bypassSuperMappings, String mapId) { if (result == null) { BeanBuilder beanBuilder = DestBeanBuilderCreator.create(creationDirective); if (beanBuilder == null) { result = (T) DestBeanCreator.create(creationDirective); mapToDestObject(classMap, srcObj, result, bypassSuperMappings, mapId); } else { mapToDestObject(classMap, srcObj, beanBuilder, bypassSuperMappings, mapId); result = (T) beanBuilder.build(); } } else { mapToDestObject(classMap, srcObj, result, bypassSuperMappings, mapId); } return result; }
private Object mapMap(Object srcObj, Map srcMapValue, FieldMap fieldMap, Object destObj) { Map result; Map destinationMap = (Map) fieldMap.getDestValue(destObj); if (destinationMap == null) { result = DestBeanCreator.create(srcMapValue.getClass()); } else { result = destinationMap; if (fieldMap.isRemoveOrphans()) { result.clear(); } } for (Entry<?, Object> srcEntry : ((Map<?, Object>) srcMapValue).entrySet()) { Object srcEntryValue = srcEntry.getValue(); if (srcEntryValue == null) { // overwrites with null in any case result.put(srcEntry.getKey(), null); continue; } Object destEntryValue = mapOrRecurseObject(srcObj, srcEntryValue, srcEntryValue.getClass(), fieldMap, destObj); Object obj = result.get(srcEntry.getKey()); if (obj != null && obj.equals(destEntryValue) && fieldMap.isNonCumulativeRelationship()) { mapToDestObject(null, srcEntryValue, obj, false, null); } else { result.put(srcEntry.getKey(), destEntryValue); } } return result; }
mapToDestObject(null, srcValue, obj, false, fieldMap.getMapId()); mappedElements.add(obj);
mapToDestObject(null, srcValue, obj, false, fieldMap.getMapId()); mappedElements.add(obj);
mapToDestObject(null, srcFieldValue, result, false, fieldMap.getMapId());