@Override protected Method getReadMethod() throws NoSuchMethodException { if (MappingUtils.isBlankOrNull(getMethodName)) { throw new MappingException("Custom Map get method not specified for field mapping to class: " + clazz + ". Perhaps the map-get-method wasn't specified in the dozer mapping file?"); } if (readMethod == null || readMethod.get() == null) { Method method = findMapMethod(clazz, getMethodName, 1); readMethod = new SoftReference<Method>(method); } return readMethod.get(); }
@Override public void setPropertyValue(Object bean, Object value, FieldMap fieldMap) { if (MappingUtils.isDeepMapping(fieldName)) { writeDeepDestinationValue(bean, value, fieldMap); } else { if (!getPropertyType().isPrimitive() || value != null) { // Check if dest value is already set and is equal to src value. If true, no need to rewrite the dest value try { // We should map null values to create a new key in the map if (value != null && getPropertyValue(bean) == value) { return; } } catch (Exception e) { // if we failed to read the value, assume we must write, and continue... } invokeWriteMethod(bean, value); } } }
String getMethod = isMapProperty ? "get" : mapGetMethod; desc = new MapPropertyDescriptor(clazz, name, isIndexed, index, setMethod, getMethod, key != null ? key : oppositeFieldName, deepIndexHintContainer);
@Override protected void invokeWriteMethod(Object target, Object value) { if (key == null) { throw new MappingException("key must be specified"); } try { ReflectionUtils.invoke(getWriteMethod(), target, new Object[]{key, value}); } catch (NoSuchMethodException e) { MappingUtils.throwMappingException(e); } }
@Override protected Object invokeReadMethod(Object target) { if (key == null) { throw new MappingException("key must be specified"); } Object result = null; try { result = ReflectionUtils.invoke(getReadMethod(), target, new Object[]{key}); } catch (NoSuchMethodException e) { MappingUtils.throwMappingException(e); } return result; }
String getMethod = isMapProperty ? "get" : mapGetMethod; desc = new MapPropertyDescriptor(clazz, name, isIndexed, index, setMethod, getMethod, key != null ? key : oppositeFieldName, srcDeepIndexHintContainer, destDeepIndexHintContainer);
@Override protected void invokeWriteMethod(Object target, Object value) { if (key == null) { throw new MappingException("key must be specified"); } try { ReflectionUtils.invoke(getWriteMethod(), target, new Object[] { key, value }); } catch (NoSuchMethodException e) { MappingUtils.throwMappingException(e); } }
@Override protected Object invokeReadMethod(Object target) { if (key == null) { throw new MappingException("key must be specified"); } Object result = null; try { result = ReflectionUtils.invoke(getReadMethod(), target, new Object[] { key }); } catch (NoSuchMethodException e) { MappingUtils.throwMappingException(e); } return result; }
@Override public void setPropertyValue(Object bean, Object value, FieldMap fieldMap) { if (MappingUtils.isDeepMapping(fieldName)) { writeDeepDestinationValue(bean, value, fieldMap); } else { if (!getPropertyType().isPrimitive() || value != null) { // Check if dest value is already set and is equal to src value. // If true, no need to rewrite the dest value try { // We should map null values to create a new key in the map if (value != null && getPropertyValue(bean) == value) { return; } } catch (Exception e) { // if we failed to read the value, assume we must write, and // continue... } invokeWriteMethod(bean, value); } } }
String getMethod = isMapProperty ? "get" : mapGetMethod; desc = new MapPropertyDescriptor(clazz, name, isIndexed,
@Override public Method getWriteMethod() throws NoSuchMethodException { if (MappingUtils.isBlankOrNull(setMethodName)) { throw new MappingException("Custom Map set method not specified for field mapping to class: " + clazz + ". Perhaps the map-set-method wasn't specified in the dozer mapping file?"); } if (writeMethod == null || writeMethod.get() == null) { Method method = findMapMethod(clazz, setMethodName, 2); writeMethod = new SoftReference<Method>(method); } return writeMethod.get(); }
@Override protected void invokeWriteMethod(Object target, Object value) { if (key == null) { throw new MappingException("key must be specified"); } try { ReflectionUtils.invoke(getWriteMethod(), target, new Object[] { key, value }); } catch (NoSuchMethodException e) { MappingUtils.throwMappingException(e); } }
@Override protected Object invokeReadMethod(Object target) { if (key == null) { throw new MappingException("key must be specified"); } Object result = null; try { result = ReflectionUtils.invoke(getReadMethod(), target, new Object[] { key }); } catch (NoSuchMethodException e) { MappingUtils.throwMappingException(e); } return result; }
@Override public void setPropertyValue(Object bean, Object value, FieldMap fieldMap) { if (MappingUtils.isDeepMapping(fieldName)) { writeDeepDestinationValue(bean, value, fieldMap); } else { if (!getPropertyType().isPrimitive() || value != null) { // Check if dest value is already set and is equal to src value. // If true, no need to rewrite the dest value try { // We should map null values to create a new key in the map if (value != null && getPropertyValue(bean) == value) { return; } } catch (Exception e) { // if we failed to read the value, assume we must write, and // continue... } invokeWriteMethod(bean, value); } } }
@Override public Object getSrcFieldValue(Object srcObj) { DozerPropertyDescriptor propDescriptor; Object targetObject = srcObj; if (getSrcFieldName().equals(DozerConstants.SELF_KEYWORD)) { propDescriptor = super.getSrcPropertyDescriptor(srcObj.getClass()); } else { Class<?> actualType = determineActualPropertyType(getSrcFieldName(), isSrcFieldIndexed(), getSrcFieldIndex(), srcObj, false); if ((getSrcFieldMapGetMethod() != null) || (this.getMapId() == null && MappingUtils.isSupportedMap(actualType) && getSrcHintContainer() == null)) { // Need to dig out actual map object by using getter on the field. Use actual map object to get the field value targetObject = super.getSrcFieldValue(srcObj); String setMethod = MappingUtils.isSupportedMap(actualType) ? "put" : getSrcFieldMapSetMethod(); String getMethod = MappingUtils.isSupportedMap(actualType) ? "get" : getSrcFieldMapGetMethod(); String key = getSrcFieldKey() != null ? getSrcFieldKey() : getDestFieldName(); propDescriptor = new MapPropertyDescriptor(actualType, getSrcFieldName(), isSrcFieldIndexed(), getDestFieldIndex(), setMethod, getMethod, key, getSrcDeepIndexHintContainer(), getDestDeepIndexHintContainer()); } else { propDescriptor = super.getSrcPropertyDescriptor(srcObj.getClass()); } } Object result = null; if (targetObject != null) { result = propDescriptor.getPropertyValue(targetObject); } return result; }
@Override public Method getWriteMethod() throws NoSuchMethodException { if (MappingUtils.isBlankOrNull(setMethodName)) { throw new MappingException( "Custom Map set method not specified for field mapping to class: " + clazz + ". Perhaps the map-set-method wasn't specified in the dozer mapping file?"); } if (writeMethod == null || writeMethod.get() == null) { Method method = findMapMethod(clazz, setMethodName, 2); writeMethod = new SoftReference<Method>(method); } return writeMethod.get(); }
return new PrepareTargetObjectResult(targetObject, new MapPropertyDescriptor(c, getDestFieldName(), isDestFieldIndexed(), getDestFieldIndex(), MappingUtils.isSupportedMap(c) ? "put" : getDestFieldMapSetMethod(),
@Override protected Method getReadMethod() throws NoSuchMethodException { if (MappingUtils.isBlankOrNull(getMethodName)) { throw new MappingException( "Custom Map get method not specified for field mapping to class: " + clazz + ". Perhaps the map-get-method wasn't specified in the dozer mapping file?"); } if (readMethod == null || readMethod.get() == null) { Method method = findMapMethod(clazz, getMethodName, 1); readMethod = new SoftReference<Method>(method); } return readMethod.get(); }
return new PrepareTargetObjectResult(targetObject, new MapPropertyDescriptor(c, getDestFieldName(), isDestFieldIndexed(), getDestFieldIndex(), MappingUtils.isSupportedMap(c) ? "put" : getDestFieldMapSetMethod(), MappingUtils.isSupportedMap(c) ? "get" : getDestFieldMapGetMethod(), getDestFieldKey() != null ? getDestFieldKey()
@Override protected Method getReadMethod() throws NoSuchMethodException { if (MappingUtils.isBlankOrNull(getMethodName)) { throw new MappingException( "Custom Map get method not specified for field mapping to class: " + clazz + ". Perhaps the map-get-method wasn't specified in the dozer mapping file?"); } if (readMethod == null || readMethod.get() == null) { Method method = findMapMethod(clazz, getMethodName, 1); readMethod = new SoftReference<Method>(method); } return readMethod.get(); }