From e44c0a6d3e8565e0fdf64fe41095b0e8b77d9fda Mon Sep 17 00:00:00 2001 From: Rutvik Pareshbhai Patel Date: Fri, 25 Mar 2022 01:33:28 -0300 Subject: [PATCH] Committing the refactoring changes for the project --- .../ma/glasnost/orika/MappingContext.java | 15 ++-- .../orika/impl/GeneratedObjectBase.java | 6 +- .../orika/impl/GeneratedObjectFactory.java | 8 +- .../generated/GeneratedPackageClass.java | 2 +- .../generator/AggregateSpecification.java | 2 +- .../impl/generator/BaseSpecification.java | 5 +- .../generator/ObjectFactoryGenerator.java | 82 +++++++++---------- .../impl/generator/SourceCodeContext.java | 2 +- .../orika/impl/generator/Specification.java | 2 +- .../glasnost/orika/impl/util/StringUtil.java | 4 +- .../orika/jsr166x/ConcurrentSkipListMap.java | 3 +- .../orika/metadata/ElementTypeClass.java | 41 ++++++++++ .../ma/glasnost/orika/metadata/Property.java | 37 +-------- .../metadata/ScoringClassMapBuilder.java | 48 ++++++----- .../TestCompilerStrategyWritingFiles.java | 4 +- 15 files changed, 141 insertions(+), 120 deletions(-) rename core/src/main/java/ma/glasnost/orika/{ => impl}/generated/GeneratedPackageClass.java (80%) create mode 100644 core/src/main/java/ma/glasnost/orika/metadata/ElementTypeClass.java diff --git a/core/src/main/java/ma/glasnost/orika/MappingContext.java b/core/src/main/java/ma/glasnost/orika/MappingContext.java index 123477bb..203f9ac5 100644 --- a/core/src/main/java/ma/glasnost/orika/MappingContext.java +++ b/core/src/main/java/ma/glasnost/orika/MappingContext.java @@ -43,7 +43,7 @@ public class MappingContext { protected List>> mappersSeen; protected Map properties; protected Map globalProperties; - protected boolean isNew = true; + protected boolean isNewConcreteClass = true; protected boolean containsCycle = true; protected int depth; protected Type resolvedSourceType; @@ -139,7 +139,7 @@ public int getDepth() { */ @SuppressWarnings("unchecked") public Type getConcreteClass(Type sourceType, Type destinationType) { - if (isNew) { + if (isNewConcreteClass) { return null; } final Type type = mapping.get(sourceType); @@ -158,7 +158,7 @@ public Type getConcreteClass(Type sourceType, Type des */ public void registerConcreteClass(Type subjectClass, Type concreteClass) { mapping.put(subjectClass, concreteClass); - isNew = false; + isNewConcreteClass = false; } /** @@ -181,7 +181,7 @@ public void cacheMappedObject(S source, Type destinationType, D d } localCache.put(source, destination); - isNew = false; + isNewConcreteClass = false; } } @@ -197,7 +197,7 @@ public void cacheMappedObject(S source, Type destinationType, D d @SuppressWarnings("unchecked") public D getMappedObject(Object source, Type destinationType) { - if (isNew || !containsCycle) { + if (isNewConcreteClass || !containsCycle) { return null; } Map localCache = (Map) typeCache.get(destinationType.getUniqueIndex()); @@ -261,7 +261,8 @@ public void beginMapping() { * the destination object being mapped into * @deprecated This variant exists for backwards compatibility only; if * overriding, override - * {@link #beginMapping(Type, Object, Type, String, Object)} + * {@link # + * //beginMapping(Type, Object, Type, String, Object)} * instead. */ @Deprecated @@ -466,7 +467,7 @@ public void reset() { resolvedSourceType = null; resolvedDestinationType = null; resolvedStrategy = null; - isNew = true; + isNewConcreteClass = true; depth = 0; } diff --git a/core/src/main/java/ma/glasnost/orika/impl/GeneratedObjectBase.java b/core/src/main/java/ma/glasnost/orika/impl/GeneratedObjectBase.java index be81a217..83dc7d1b 100644 --- a/core/src/main/java/ma/glasnost/orika/impl/GeneratedObjectBase.java +++ b/core/src/main/java/ma/glasnost/orika/impl/GeneratedObjectBase.java @@ -88,11 +88,7 @@ protected static List asList(Iterable iterable) { } return ts; } - - protected static List asList(Object[] iterable) { - return new ArrayList<>(Arrays.asList(iterable)); - } - + protected static List asList(byte[] iterable) { ArrayList ts = new ArrayList<>(); for (Object i : iterable) { diff --git a/core/src/main/java/ma/glasnost/orika/impl/GeneratedObjectFactory.java b/core/src/main/java/ma/glasnost/orika/impl/GeneratedObjectFactory.java index 848fd50e..3d7f5b54 100644 --- a/core/src/main/java/ma/glasnost/orika/impl/GeneratedObjectFactory.java +++ b/core/src/main/java/ma/glasnost/orika/impl/GeneratedObjectFactory.java @@ -20,6 +20,12 @@ import ma.glasnost.orika.ObjectFactory; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + public abstract class GeneratedObjectFactory extends GeneratedObjectBase implements ObjectFactory { - + protected static List asList(Object[] iterable) { + return new ArrayList<>(Arrays.asList(iterable)); + } } diff --git a/core/src/main/java/ma/glasnost/orika/generated/GeneratedPackageClass.java b/core/src/main/java/ma/glasnost/orika/impl/generated/GeneratedPackageClass.java similarity index 80% rename from core/src/main/java/ma/glasnost/orika/generated/GeneratedPackageClass.java rename to core/src/main/java/ma/glasnost/orika/impl/generated/GeneratedPackageClass.java index 24e444fb..56e49354 100644 --- a/core/src/main/java/ma/glasnost/orika/generated/GeneratedPackageClass.java +++ b/core/src/main/java/ma/glasnost/orika/impl/generated/GeneratedPackageClass.java @@ -1,4 +1,4 @@ -package ma.glasnost.orika.generated; +package ma.glasnost.orika.impl.generated; /** * This interface is used as a parameter during class generation in order to be able to avoid Illegal reflective access diff --git a/core/src/main/java/ma/glasnost/orika/impl/generator/AggregateSpecification.java b/core/src/main/java/ma/glasnost/orika/impl/generator/AggregateSpecification.java index c8a02b45..7c9c0d55 100644 --- a/core/src/main/java/ma/glasnost/orika/impl/generator/AggregateSpecification.java +++ b/core/src/main/java/ma/glasnost/orika/impl/generator/AggregateSpecification.java @@ -32,7 +32,7 @@ */ public interface AggregateSpecification extends BaseSpecification { - void setMapperFactory(MapperFactory mapperFactory); + /** * @param fieldMappings diff --git a/core/src/main/java/ma/glasnost/orika/impl/generator/BaseSpecification.java b/core/src/main/java/ma/glasnost/orika/impl/generator/BaseSpecification.java index 3369993f..37a4728a 100644 --- a/core/src/main/java/ma/glasnost/orika/impl/generator/BaseSpecification.java +++ b/core/src/main/java/ma/glasnost/orika/impl/generator/BaseSpecification.java @@ -1,5 +1,5 @@ package ma.glasnost.orika.impl.generator; - +import ma.glasnost.orika.MapperFactory; import ma.glasnost.orika.metadata.FieldMap; /** @@ -16,4 +16,7 @@ public interface BaseSpecification { * @return true if this specification applies to the given MappedTypePair */ boolean appliesTo(FieldMap fieldMap); + + + void setMapperFactory(MapperFactory mapperFactory); } diff --git a/core/src/main/java/ma/glasnost/orika/impl/generator/ObjectFactoryGenerator.java b/core/src/main/java/ma/glasnost/orika/impl/generator/ObjectFactoryGenerator.java index 350939c8..c1cac1be 100644 --- a/core/src/main/java/ma/glasnost/orika/impl/generator/ObjectFactoryGenerator.java +++ b/core/src/main/java/ma/glasnost/orika/impl/generator/ObjectFactoryGenerator.java @@ -46,27 +46,27 @@ * ObjectFactory capable of instantiating a given target type. */ public class ObjectFactoryGenerator { - + private final static Logger LOGGER = LoggerFactory.getLogger(ObjectFactoryGenerator.class); - + private final ConstructorResolverStrategy constructorResolverStrategy; private final MapperFactory mapperFactory; private final String nameSuffix; - + /** * Creates a new ObjectFactoryGenerator instance - * + * * @param mapperFactory * @param constructorResolverStrategy * @param compilerStrategy */ public ObjectFactoryGenerator(MapperFactory mapperFactory, ConstructorResolverStrategy constructorResolverStrategy, - CompilerStrategy compilerStrategy) { + CompilerStrategy compilerStrategy) { this.mapperFactory = mapperFactory; this.nameSuffix = String.valueOf(System.nanoTime()); this.constructorResolverStrategy = constructorResolverStrategy; } - + /** * @param type * @param sourceType @@ -74,7 +74,7 @@ public ObjectFactoryGenerator(MapperFactory mapperFactory, ConstructorResolverSt * @return an instance of the newly generated ObjectFactory */ public GeneratedObjectFactory build(Type type, Type sourceType, MappingContext context) { - + String className = type.getSimpleName() + "_" + sourceType.getSimpleName() + "_ObjectFactory" + nameSuffix; try { StringBuilder logDetails; @@ -89,22 +89,22 @@ public GeneratedObjectFactory build(Type type, Type sourceType, MappingCon final SourceCodeContext factoryCode = new SourceCodeContext(className, packageNeighbour, GeneratedObjectFactory.class, context, logDetails); - + UsedTypesContext usedTypes = new UsedTypesContext(); UsedConvertersContext usedConverters = new UsedConvertersContext(); UsedMapperFacadesContext usedMapperFacades = new UsedMapperFacadesContext(); - + addCreateMethod(factoryCode, usedTypes, usedConverters, usedMapperFacades, type, sourceType, context, logDetails); - + GeneratedObjectFactory objectFactory = (GeneratedObjectFactory) factoryCode.getInstance(); objectFactory.setMapperFacade(mapperFactory.getMapperFacade()); - + if (logDetails != null) { LOGGER.debug(logDetails.toString()); } - + return objectFactory; - + } catch (final Exception e) { if (e instanceof MappingException) { throw (MappingException) e; @@ -120,21 +120,21 @@ private static String getPackageName(Type type) { } private void addCreateMethod(SourceCodeContext code, UsedTypesContext usedTypes, UsedConvertersContext usedConverters, - UsedMapperFacadesContext usedMappers, Type type, Type sourceType, MappingContext mappingContext, StringBuilder logDetails) { - + UsedMapperFacadesContext usedMappers, Type type, Type sourceType, MappingContext mappingContext, StringBuilder logDetails) { + final StringBuilder out = new StringBuilder(); out.append("public Object create(Object s, ").append(MappingContext.class.getCanonicalName()).append(" mappingContext) {"); out.append(format("if(s == null) throw new %s(\"source object must be not null\");", IllegalArgumentException.class.getCanonicalName())); - + out.append(addSourceClassConstructor(code, type, sourceType, mappingContext, logDetails)); out.append(addUnmatchedSourceHandler(code, type, sourceType, mappingContext, logDetails)); - + out.append("\n}"); - + code.addMethod(out.toString()); } - + /** * @param code * @param destinationType @@ -144,38 +144,38 @@ private void addCreateMethod(SourceCodeContext code, UsedTypesContext usedTypes, * @return */ private String addSourceClassConstructor(SourceCodeContext code, Type destinationType, Type sourceType, - MappingContext mappingContext, StringBuilder logDetails) { - + MappingContext mappingContext, StringBuilder logDetails) { + MapperKey mapperKey = new MapperKey(sourceType, destinationType); ClassMap classMap = mapperFactory.getClassMap(mapperKey); - + if (classMap == null) { classMap = mapperFactory.getClassMap(new MapperKey(destinationType, sourceType)); } - + StringBuilder out = new StringBuilder(); if (classMap != null) { if (destinationType.isArray()) { out.append(addArrayClassConstructor(code, destinationType, sourceType, classMap.getFieldsMapping().size())); } else { - + out.append(format("if (s instanceof %s) {", sourceType.getCanonicalName())); out.append(format("%s source = (%s) s;", sourceType.getCanonicalName(), sourceType.getCanonicalName())); out.append("\ntry {\n"); - + ConstructorMapping constructorMapping = (ConstructorMapping) constructorResolverStrategy.resolve(classMap, destinationType); Constructor constructor = constructorMapping.getConstructor(); - + if (constructor == null) { throw new IllegalArgumentException("no suitable constructors found for " + destinationType); } else if (logDetails != null) { logDetails.append("\n\tUsing constructor: ").append(constructor); } - + List properties = constructorMapping.getMappedFields(); Type[] constructorArguments = constructorMapping.getParameterTypes(); - + if (constructorArguments == null || properties.size() != constructorArguments.length) { throw new MappingException("While attempting to generate ObjectFactory using constructor '" + constructor + "', an automatic mapping of the source type ('" + sourceType @@ -183,11 +183,11 @@ private String addSourceClassConstructor(SourceCodeContext code, Type destina + "register a custom ObjectFactory implementation which is able to create an instance of '" + destinationType + "' from an instance of '" + sourceType + "'."); } - + int argIndex = 0; - + argIndex = 0; - + for (FieldMap fieldMap : properties) { VariableRef v = new VariableRef(constructorArguments[argIndex], "arg" + argIndex++); VariableRef s = new VariableRef(fieldMap.getSource(), "source"); @@ -196,7 +196,7 @@ private String addSourceClassConstructor(SourceCodeContext code, Type destina out.append(statement(v.declare())); out.append(code.mapFields(fieldMap, s, v)); } - + out.append(format("return new %s(", destinationType.getCanonicalName())); for (int i = 0; i < properties.size(); i++) { out.append(format("arg%d", i)); @@ -216,11 +216,11 @@ private String addSourceClassConstructor(SourceCodeContext code, Type destina } return out.toString(); } - + /** * Adds a default constructor call (where possible) as fail-over case when * no specific source type has been matched. - * + * * @param code * @param type * @param mappingContext @@ -228,7 +228,7 @@ private String addSourceClassConstructor(SourceCodeContext code, Type destina * @return */ private String addUnmatchedSourceHandler(SourceCodeContext code, Type type, Type sourceType, MappingContext mappingContext, - StringBuilder logDetails) { + StringBuilder logDetails) { StringBuilder out = new StringBuilder(); for (Constructor constructor : type.getRawType().getConstructors()) { if (constructor.getParameterTypes().length == 0 && Modifier.isPublic(constructor.getModifiers())) { @@ -236,7 +236,7 @@ private String addUnmatchedSourceHandler(SourceCodeContext code, Type type, T break; } } - + /* * If no default constructor field exists, attempt to locate and call a * constructor which takes a single argument of source type @@ -252,17 +252,17 @@ private String addUnmatchedSourceHandler(SourceCodeContext code, Type type, T } } } - + if (out.length() == 0) { - + out.append(format( "throw new %s(s.getClass().getCanonicalName() + \" is an unsupported source class for constructing instances of " + type.getCanonicalName() + "\");", IllegalArgumentException.class.getCanonicalName())); } - + return out.toString(); } - + /** * @param type * @param size @@ -271,4 +271,4 @@ private String addArrayClassConstructor(SourceCodeContext code, Type type, Ty return format("if (s instanceof %s) {", sourceType.getCanonicalName()) + "return new " + type.getRawType().getComponentType().getCanonicalName() + "[" + size + "];" + "\n}"; } -} +} \ No newline at end of file diff --git a/core/src/main/java/ma/glasnost/orika/impl/generator/SourceCodeContext.java b/core/src/main/java/ma/glasnost/orika/impl/generator/SourceCodeContext.java index cf1ee9ed..f4787567 100644 --- a/core/src/main/java/ma/glasnost/orika/impl/generator/SourceCodeContext.java +++ b/core/src/main/java/ma/glasnost/orika/impl/generator/SourceCodeContext.java @@ -26,7 +26,7 @@ import ma.glasnost.orika.MappingContext; import ma.glasnost.orika.Properties; import ma.glasnost.orika.converter.ConverterFactory; -import ma.glasnost.orika.generated.GeneratedPackageClass; +import ma.glasnost.orika.impl.generated.GeneratedPackageClass; import ma.glasnost.orika.impl.AggregateFilter; import ma.glasnost.orika.impl.GeneratedObjectBase; import ma.glasnost.orika.impl.generator.CompilerStrategy.SourceCodeGenerationException; diff --git a/core/src/main/java/ma/glasnost/orika/impl/generator/Specification.java b/core/src/main/java/ma/glasnost/orika/impl/generator/Specification.java index 8e364861..50b75bf5 100644 --- a/core/src/main/java/ma/glasnost/orika/impl/generator/Specification.java +++ b/core/src/main/java/ma/glasnost/orika/impl/generator/Specification.java @@ -30,7 +30,7 @@ */ public interface Specification extends BaseSpecification { - void setMapperFactory(MapperFactory mapperFactory); + /** * Generates code for a boolean equality test between the two variable types, diff --git a/core/src/main/java/ma/glasnost/orika/impl/util/StringUtil.java b/core/src/main/java/ma/glasnost/orika/impl/util/StringUtil.java index 63d84eb6..e2baf7ca 100644 --- a/core/src/main/java/ma/glasnost/orika/impl/util/StringUtil.java +++ b/core/src/main/java/ma/glasnost/orika/impl/util/StringUtil.java @@ -42,7 +42,7 @@ public static String capitalize(String string) { *

Uncapitalizes a String, changing the first character to lower case as per {@link * Character#toLowerCase(char)}. No other characters are changed.

* - *

For a word based algorithm, see {@link org.apache.commons.lang3.text.WordUtils#uncapitalize(String)}. + *

For a word based algorithm, see {@link //org.apache.commons.lang3.text.WordUtils#uncapitalize(String)}. * A {@code null} input String returns {@code null}.

* *
@@ -55,7 +55,7 @@ public static String capitalize(String string) {
      *
      * @param str the String to uncapitalize, may be null
      * @return the uncapitalized String, {@code null} if null String input
-     * @see org.apache.commons.lang3.text.WordUtils#uncapitalize(String)
+     * @see //org.apache.commons.lang3.text.WordUtils#uncapitalize(String)
      * @see #capitalize(String)
      * @since 2.0
      */
diff --git a/core/src/main/java/ma/glasnost/orika/jsr166x/ConcurrentSkipListMap.java b/core/src/main/java/ma/glasnost/orika/jsr166x/ConcurrentSkipListMap.java
index 0b229ad5..0c0edfcf 100644
--- a/core/src/main/java/ma/glasnost/orika/jsr166x/ConcurrentSkipListMap.java
+++ b/core/src/main/java/ma/glasnost/orika/jsr166x/ConcurrentSkipListMap.java
@@ -447,7 +447,8 @@ boolean casNext(Node cmp, Node val) {
          * because callers will have already read value field and need
          * to use that read (not another done here) and so directly
          * test if value points to node.
-         * @param n a possibly null reference to a node
+         * @param
+         * //n a possibly null reference to a node
          * @return true if this node is a marker node
          */
         boolean isMarker() {
diff --git a/core/src/main/java/ma/glasnost/orika/metadata/ElementTypeClass.java b/core/src/main/java/ma/glasnost/orika/metadata/ElementTypeClass.java
new file mode 100644
index 00000000..594a2eae
--- /dev/null
+++ b/core/src/main/java/ma/glasnost/orika/metadata/ElementTypeClass.java
@@ -0,0 +1,41 @@
+package ma.glasnost.orika.metadata;
+
+import ma.glasnost.orika.MapEntry;
+
+import java.util.Collection;
+import java.util.Map;
+
+public class ElementTypeClass {
+
+    static Type defaultElementType(final Type type, final Type elementType) {
+
+        if (elementType != null) {
+            return elementType;
+        }
+
+        if (type.getActualTypeArguments().length > 0 && elementType == null) {
+            return (Type) type.getActualTypeArguments()[0];
+        } else if (type.isCollection()) {
+            Type collectionElementType = elementType;
+            Type collection = type.findAncestor(Collection.class);
+            if (collection != null) {
+                collectionElementType = (Type) collection.getActualTypeArguments()[0];
+            }
+            return collectionElementType;
+
+        } else if (type.isMap()) {
+
+            Type mapElementType = elementType;
+            Type map = type.findAncestor(Map.class);
+            if (map != null) {
+                @SuppressWarnings("unchecked")
+                Type> mapType = (Type>) map;
+                mapElementType = MapEntry.entryType(mapType);
+            }
+            return mapElementType;
+
+        } else {
+            return elementType;
+        }
+    }
+}
diff --git a/core/src/main/java/ma/glasnost/orika/metadata/Property.java b/core/src/main/java/ma/glasnost/orika/metadata/Property.java
index 767d7576..982747f1 100644
--- a/core/src/main/java/ma/glasnost/orika/metadata/Property.java
+++ b/core/src/main/java/ma/glasnost/orika/metadata/Property.java
@@ -18,7 +18,6 @@
 
 package ma.glasnost.orika.metadata;
 
-import ma.glasnost.orika.MapEntry;
 import ma.glasnost.orika.property.PropertyResolver;
 
 import java.lang.reflect.Method;
@@ -65,43 +64,11 @@ protected Property(final String expression, final String name, final String gett
         this.getter = getter;
         this.setter = setter;
         this.type = type;
-        this.elementType = defaultElementType(type, elementType);
+        this.elementType = ElementTypeClass.defaultElementType(type, elementType);
         
         this.container = container;
     }
-    
-    private static Type defaultElementType(final Type type, final Type elementType) {
-        
-        if (elementType != null) {
-            return elementType;
-        }
-        
-        if (type.getActualTypeArguments().length > 0 && elementType == null) {
-            return (Type) type.getActualTypeArguments()[0];
-        } else if (type.isCollection()) {
-            Type collectionElementType = elementType;
-            Type collection = type.findAncestor(Collection.class);
-            if (collection != null) {
-                collectionElementType = (Type) collection.getActualTypeArguments()[0];
-            }
-            return collectionElementType;
-            
-        } else if (type.isMap()) {
-            
-            Type mapElementType = elementType;
-            Type map = type.findAncestor(Map.class);
-            if (map != null) {
-                @SuppressWarnings("unchecked")
-                Type> mapType = (Type>) map;
-                mapElementType = MapEntry.entryType(mapType);
-            }
-            return mapElementType;
-            
-        } else {
-            return elementType;
-        }
-    }
-    
+
     /**
      * @return a copy of this property instance
      */
diff --git a/core/src/main/java/ma/glasnost/orika/metadata/ScoringClassMapBuilder.java b/core/src/main/java/ma/glasnost/orika/metadata/ScoringClassMapBuilder.java
index 2bb2ce97..66f6094a 100644
--- a/core/src/main/java/ma/glasnost/orika/metadata/ScoringClassMapBuilder.java
+++ b/core/src/main/java/ma/glasnost/orika/metadata/ScoringClassMapBuilder.java
@@ -254,11 +254,33 @@ public ClassMapBuilder byDefault(MappingDirection direction, DefaultFieldM
          * For our custom 'byDefault' method, we're going to try and match
          * fields by their Levenshtein distance
          */
+        Set unmatchedFields = getUnmatchedFields(direction);
+
+        /*
+         * Apply any default field mappers to the unmapped fields
+         */
+        for (String propertyNameA : unmatchedFields) {
+            Property prop = resolvePropertyForA(propertyNameA);
+            for (DefaultFieldMapper defaulter : defaults) {
+                String suggestion = defaulter.suggestMappedField(propertyNameA, prop.getType());
+                if (suggestion != null && getPropertiesForTypeB().contains(suggestion)) {
+                    if (!getMappedPropertiesForTypeB().contains(suggestion)) {
+                        fieldMap(propertyNameA, suggestion).direction(direction).add();
+                    }
+                }
+            }
+        }
+        
+        return this;
+    }
+
+    private Set getUnmatchedFields(MappingDirection direction) {
         PriorityQueue matchScores = new PriorityQueue<>();
         
+
         Map propertiesForA = getPropertyExpressions(getAType());
         Map propertiesForB = getPropertyExpressions(getBType());
-        
+
         for (final Entry propertyA : propertiesForA.entrySet()) {
             if (!propertyA.getValue().getName().equals("class")) {
                 for (final Entry propertyB : propertiesForB.entrySet()) {
@@ -269,10 +291,10 @@ public ClassMapBuilder byDefault(MappingDirection direction, DefaultFieldM
                 }
             }
         }
-        
+
         Set unmatchedFields = new LinkedHashSet<>(this.getPropertiesForTypeA());
         unmatchedFields.remove("class");
-        
+
         for (FieldMatchScore score : matchScores) {
             
             if (!this.getMappedPropertiesForTypeA().contains(score.propertyA.getExpression())
@@ -286,25 +308,9 @@ public ClassMapBuilder byDefault(MappingDirection direction, DefaultFieldM
                 }
             }
         }
-        
-        /*
-         * Apply any default field mappers to the unmapped fields
-         */
-        for (String propertyNameA : unmatchedFields) {
-            Property prop = resolvePropertyForA(propertyNameA);
-            for (DefaultFieldMapper defaulter : defaults) {
-                String suggestion = defaulter.suggestMappedField(propertyNameA, prop.getType());
-                if (suggestion != null && getPropertiesForTypeB().contains(suggestion)) {
-                    if (!getMappedPropertiesForTypeB().contains(suggestion)) {
-                        fieldMap(propertyNameA, suggestion).direction(direction).add();
-                    }
-                }
-            }
-        }
-        
-        return this;
+        return unmatchedFields;
     }
-    
+
     /**
      * @author mattdeboer
      *
diff --git a/core/src/test/java/ma/glasnost/orika/test/generator/TestCompilerStrategyWritingFiles.java b/core/src/test/java/ma/glasnost/orika/test/generator/TestCompilerStrategyWritingFiles.java
index 27df8327..996d3877 100644
--- a/core/src/test/java/ma/glasnost/orika/test/generator/TestCompilerStrategyWritingFiles.java
+++ b/core/src/test/java/ma/glasnost/orika/test/generator/TestCompilerStrategyWritingFiles.java
@@ -73,12 +73,12 @@ public static void tearDown() {
     	File generatedBinFiles = null;
     	try {
     		Assert.assertTrue(generatedSrc.exists());
-    		generatedSrcFiles = new File(generatedSrc,"ma/glasnost/orika/generated/");
+    		generatedSrcFiles = new File(generatedSrc, "ma/glasnost/orika/impl/generated/");
         	Assert.assertTrue(generatedSrcFiles.isDirectory());
         	Assert.assertTrue(generatedSrcFiles.listFiles().length > 0);
         	
         	Assert.assertTrue(generatedBin.exists());
-        	generatedBinFiles = new File(generatedBin,"ma/glasnost/orika/generated/");
+        	generatedBinFiles = new File(generatedBin, "ma/glasnost/orika/impl/generated/");
         	Assert.assertTrue(generatedBinFiles.isDirectory());
         	Assert.assertTrue(generatedBinFiles.listFiles().length > 0);