From f692c765d24d674d50e4bef8bcb05a095775ae3d Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Wed, 7 Oct 2009 17:50:03 +0000 Subject: [PATCH] addNestedMapper --- .../springframework/mapping/support/SpelMapper.java | 10 ++++++++++ .../core/convert/support/GenericConversionService.java | 10 +++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/org.springframework.context/src/main/java/org/springframework/mapping/support/SpelMapper.java b/org.springframework.context/src/main/java/org/springframework/mapping/support/SpelMapper.java index 3a6776b226c..628da8539c1 100644 --- a/org.springframework.context/src/main/java/org/springframework/mapping/support/SpelMapper.java +++ b/org.springframework.context/src/main/java/org/springframework/mapping/support/SpelMapper.java @@ -115,6 +115,16 @@ public class SpelMapper implements Mapper { return mapping; } + /** + * Adds a Mapper to apply to complex nested property mappings of a specific sourceType/targetType pair. + * @param sourceType the source nested property type + * @param targetType the target nested property type + * @param nestedMapper the nested mapper + */ + public void addNestedMapper(Class sourceType, Class targetType, Mapper nestedMapper) { + this.conversionService.addGenericConverter(sourceType, targetType, new MapperConverter(nestedMapper)); + } + /** * Return this mapper's converter registry. * Allows for registration of simple type converters as well as converters that map nested objects using a Mapper. diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java index c292a5c1807..a586ed54bbb 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java @@ -183,15 +183,13 @@ public class GenericConversionService implements ConversionService, ConverterReg return invokeConverter(converter, source, sourceType, targetType); } - // subclassing hooks - /** * Registers a GenericConverter. * @param sourceType the source type to convert from * @param targetType the target type to convert to * @param converter the generic converter. */ - protected void addGenericConverter(Class sourceType, Class targetType, GenericConverter converter) { + public void addGenericConverter(Class sourceType, Class targetType, GenericConverter converter) { getSourceMap(sourceType).put(targetType, converter); } @@ -202,7 +200,7 @@ public class GenericConversionService implements ConversionService, ConverterReg * @param targetType the target type to convert to * @param converter the converter. */ - protected void addConverter(Class sourceType, Class targetType, Converter converter) { + public void addConverter(Class sourceType, Class targetType, Converter converter) { addGenericConverter(sourceType, targetType, new ConverterAdapter(converter)); } @@ -213,10 +211,12 @@ public class GenericConversionService implements ConversionService, ConverterReg * @param targetType the target type to convert to * @param converter the converter.factory */ - protected void addConverterFactory(Class sourceType, Class targetType, ConverterFactory converterFactory) { + public void addConverterFactory(Class sourceType, Class targetType, ConverterFactory converterFactory) { addGenericConverter(sourceType, targetType, new ConverterFactoryAdapter(converterFactory)); } + // subclassing hooks + /** * Hook method to convert a null source. * Default implementation returns null.