Author: gk
Date: Thu Apr 30 15:20:06 2015
New Revision: 1677013

URL: http://svn.apache.org/r1677013
Log:
- added cache service
- adding convenience methods 
- removing some method calls having null arguments
- junit 3 -> 4 in master pom, with dependency to SNAPSHOT testcontainer

Added:
    
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/CacheService.java
   (with props)
    
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/CustomModule.java
   (with props)
    
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/MixinModule.java
   (with props)
Modified:
    turbine/fulcrum/trunk/json/api/pom.xml
    
turbine/fulcrum/trunk/json/api/src/java/org/apache/fulcrum/json/JsonService.java
    
turbine/fulcrum/trunk/json/api/src/test/org/apache/fulcrum/json/DummTest.java
    turbine/fulcrum/trunk/json/gson/pom.xml
    
turbine/fulcrum/trunk/json/gson/src/java/org/apache/fulcrum/json/gson/GSONBuilderService.java
    
turbine/fulcrum/trunk/json/gson/src/test/org/apache/fulcrum/json/gson/DefaultServiceTest.java
    turbine/fulcrum/trunk/json/jackson/pom.xml
    
turbine/fulcrum/trunk/json/jackson/src/java/org/apache/fulcrum/json/jackson/JacksonMapperService.java
    
turbine/fulcrum/trunk/json/jackson/src/test/org/apache/fulcrum/json/jackson/DefaultServiceTest.java
    turbine/fulcrum/trunk/json/jackson2/pom.xml
    
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/Jackson2MapperService.java
    
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/SimpleNameIntrospector.java
    
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/filters/CustomModuleWrapper.java
    
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/DefaultServiceTest.java
    
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JacksonMapperEnabledDefaultTyping_OBJECT_AND_NON_CONCRETE_Test.java
    
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JacksonMapperTest.java
    turbine/fulcrum/trunk/json/pom.xml

Modified: turbine/fulcrum/trunk/json/api/pom.xml
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/api/pom.xml?rev=1677013&r1=1677012&r2=1677013&view=diff
==============================================================================
--- turbine/fulcrum/trunk/json/api/pom.xml (original)
+++ turbine/fulcrum/trunk/json/api/pom.xml Thu Apr 30 15:20:06 2015
@@ -48,24 +48,6 @@
             <artifactId>avalon-framework-api</artifactId>
             <version>4.3.1</version>
         </dependency>
-        <dependency>
-            <groupId>org.apache.fulcrum</groupId>
-            <artifactId>fulcrum-crypto</artifactId>
-            <version>1.0.7</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.fulcrum</groupId>
-            <artifactId>fulcrum-testcontainer</artifactId>
-            <version>1.0.6</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.fulcrum</groupId>
-            <artifactId>fulcrum-yaafi</artifactId>
-            <version>1.0.6</version>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
     <build>
         <sourceDirectory>src/java</sourceDirectory>

Modified: 
turbine/fulcrum/trunk/json/api/src/java/org/apache/fulcrum/json/JsonService.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/api/src/java/org/apache/fulcrum/json/JsonService.java?rev=1677013&r1=1677012&r2=1677013&view=diff
==============================================================================
--- 
turbine/fulcrum/trunk/json/api/src/java/org/apache/fulcrum/json/JsonService.java
 (original)
+++ 
turbine/fulcrum/trunk/json/api/src/java/org/apache/fulcrum/json/JsonService.java
 Thu Apr 30 15:20:06 2015
@@ -119,11 +119,34 @@ public interface JsonService {
      */
     <T> Collection<T> deSerCollection(String json, Object collectionType, 
Class<T> elementType) 
             throws Exception;
+    
+    /**
+     * Custom method without caching. Caching is set to <code>false</code> for 
this method call.
+     * @see #serializeOnlyFilter(Object, Class, Boolean, String...).
+     * 
+     * <code>refreshFilter</code> is set to <code>true</code> for this method 
call.
+     */
+    public <T> String serializeOnlyFilter(Object src, 
+            String... filterAttr) throws Exception;
+    
+    /**
+     * Custom method. Caching key is derived from param src object class. 
+     * @see #serializeOnlyFilter(Object, Class, Boolean, String...).
+     * 
+     * @param src
+     *            The Java object to serialize
+     * @param cleanFilter
+     *             The Boolean value, not null. If it is <code>true</code>, 
cleans cache and the custom filter after serialization.
+     * 
+     * <code>refreshFilter</code> is set to <code>true</code> for this method 
call.
+     */
+    public <T> String serializeOnlyFilter(Object src, Boolean cleanFilter,
+            String... filterAttr) throws Exception;
 
     /**
      * @see #serializeOnlyFilter(Object, Class, Boolean, String...).
      * 
-     * <code>refreshFilter</code> is set to <code>false</code> for this method 
call.
+     * Caching is set to <code>false</code> for this method call.
      */
     public <T> String serializeOnlyFilter(Object src, Class<T> filterClass,
             String... filterAttr) throws Exception;
@@ -132,20 +155,20 @@ public interface JsonService {
      * Serialize only object properties where filter attributes are provided
      * 
      * @param src
-     *            the Java object to serialize
+     *            The Java object to serialize
      * @param filterClass
-     *            the class to which the filtering should be applied
+     *            By default filterClass is the key in the filter object 
cached. 
      *            
      * @param cleanFilter
-     *             the Boolean value, not null. If it is <code>true</code>, 
cleans cache and the custom filter after serialization.
+     *             The Boolean value, not null. If it is <code>true</code>, 
cleans cache and the custom filter after serialization.
      *  
      * @param filterAttr
-     *            the class bean attributes which should be serialized
+     *            The class bean attributes which should be serialized
      * 
      * @return JSON string
      * 
      * @throws Exception
-     *             if JSON serialization or filter registration fails
+     *             If JSON serialization or filter registration fails
      */
     public <T> String serializeOnlyFilter(Object src, Class<T> filterClass, 
Boolean cleanFilter,
             String... filterAttr) throws Exception;
@@ -154,32 +177,48 @@ public interface JsonService {
      * Serialize all object properties excluding provided filters attributes
      * 
      * @param src
-     *            the Java object to serialize
+     *            The Java object to serialize
      * @param filterClass
-     *            the class to which the filtering should be applied. If its 
the
-     *            same class, just the filterAttributes get applied. If not the
-     *            class is filtered out, if found as a property type.
+     *            The class to which the filtering should be applied. If its 
the
+     *            same class, just the filterAttributes get applied. If not, 
the
+     *            class is filtered out, if found as a property type. By 
default filterClass is the key in the filter object cached. 
      * @param cleanFilter
-     *            if <code>true </code> cleans filter (clean cache and custom 
filter for this filterClass) after serialization.      
-     * 
+     *            If <code>true </code> cleans filter (clean cache and custom 
filter for this filterClass) after serialization.      
      * @param filterAttr
-     *            the bean attributes which should not be serialized
+     *            The bean attributes which should not be serialized
      * 
      * @return JSON string
      * 
      * @throws Exception
-     *             if JSON serialization or filter registration fails
+     *             If JSON serialization or filter registration fails
      */
     public <T> String serializeAllExceptFilter(Object src,
             Class<T> filterClass, Boolean cleanFilter, String... filterAttr) 
throws Exception;
     
     /** 
+     *  Class Filter is derived from param src object class.
+     *  <code>refreshFilter</code> is set to <code>false</code> for this 
method call.
+     *  
      * @see #serializeAllExceptFilter(Object, Class, Boolean, String...)
      * 
      * <code>refreshFilter</code> is <code>false</code>.
      */
     public <T> String serializeAllExceptFilter(Object src,
             Class<T> filterClass, String... filterAttr) throws Exception;
+    
+    /**
+     * Class Filter is derived from param src object class. 
+     * 
+     * @see #serializeAllExceptFilter(Object, Class, Boolean, String...)
+     */
+    public <T> String serializeAllExceptFilter(Object src,
+            Boolean cleanFilter, String... filterAttr) throws Exception;
+    
+    /**
+     *  @see #serializeAllExceptFilter(Object, Class, Boolean, String...)
+     */
+    public <T> String serializeAllExceptFilter(Object src,
+            String... filterAttr) throws Exception;
 
     /**
      * Adds an adapter (mixin, serializer,..) for the target class depending on
@@ -187,16 +226,16 @@ public interface JsonService {
      * Cft. to {@link #addAdapter(String, Class, Object)}
      * 
      * @param name
-     *            the name of the adapter
+     *            The name of the adapter
      * @param target
-     *            the target class for this adapter
+     *            The target class for this adapter
      * @param mixin
-     *            the adapter/mixin for the target class
+     *            The adapter/mixin for the target class
      * 
      * @return the JsonService instance
      * 
      * @throws Exception
-     *             if adapter registration fails
+     *             If adapter registration fails
      */
     public JsonService addAdapter(String name, Class target, Class mixin)
             throws Exception;
@@ -208,14 +247,14 @@ public interface JsonService {
      * implementation) 
      * 
      * @param name
-     *            the name of the adapter
+     *            The name of the adapter
      * @param target
-     *            the target class for this adapter
+     *            The target class for this adapter
      * @param mixin
-     *            the adapter/mixin for the target object
+     *            The adapter/mixin for the target object
      *            (module/serializer/deserializer)
      * 
-     * @return a JsonService instance
+     * @return A JsonService instance
      * 
      * @throws Exception
      *             if adapter registration fails
@@ -225,7 +264,7 @@ public interface JsonService {
 
     /**
      * @param df
-     *            the {@link DateFormat} to be used by the JsonService, not 
null.
+     *            The {@link DateFormat} to be used by the JsonService, not 
null.
      * 
      * It could be provided by component configuration too.
      * 

Modified: 
turbine/fulcrum/trunk/json/api/src/test/org/apache/fulcrum/json/DummTest.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/api/src/test/org/apache/fulcrum/json/DummTest.java?rev=1677013&r1=1677012&r2=1677013&view=diff
==============================================================================
--- 
turbine/fulcrum/trunk/json/api/src/test/org/apache/fulcrum/json/DummTest.java 
(original)
+++ 
turbine/fulcrum/trunk/json/api/src/test/org/apache/fulcrum/json/DummTest.java 
Thu Apr 30 15:20:06 2015
@@ -1,9 +1,11 @@
 package org.apache.fulcrum.json;
 
-import junit.framework.TestCase;
+import org.junit.Test;
 
-public class DummTest extends TestCase {
 
+public class DummTest  {
+
+    @Test
     public void testDummy() {
 
     }

Modified: turbine/fulcrum/trunk/json/gson/pom.xml
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/gson/pom.xml?rev=1677013&r1=1677012&r2=1677013&view=diff
==============================================================================
--- turbine/fulcrum/trunk/json/gson/pom.xml (original)
+++ turbine/fulcrum/trunk/json/gson/pom.xml Thu Apr 30 15:20:06 2015
@@ -84,18 +84,6 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>3.8.1</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.fulcrum</groupId>
-            <artifactId>fulcrum-testcontainer</artifactId>
-            <version>1.0.6</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
             <groupId>org.apache.fulcrum</groupId>
             <artifactId>fulcrum-yaafi</artifactId>
             <version>1.0.6</version>

Modified: 
turbine/fulcrum/trunk/json/gson/src/java/org/apache/fulcrum/json/gson/GSONBuilderService.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/gson/src/java/org/apache/fulcrum/json/gson/GSONBuilderService.java?rev=1677013&r1=1677012&r2=1677013&view=diff
==============================================================================
--- 
turbine/fulcrum/trunk/json/gson/src/java/org/apache/fulcrum/json/gson/GSONBuilderService.java
 (original)
+++ 
turbine/fulcrum/trunk/json/gson/src/java/org/apache/fulcrum/json/gson/GSONBuilderService.java
 Thu Apr 30 15:20:06 2015
@@ -101,7 +101,22 @@ public class GSONBuilderService extends
         getLogger().debug("collectionType:" + collectionType);
         return  gson.create().fromJson(json, (Type)collectionType);
     }
-    
+
+    @Override
+    public <T> String serializeOnlyFilter(Object src, String... filterAttr)
+            throws Exception {
+        return  gson
+                .addSerializationExclusionStrategy(
+                        include(null,filterAttr)).create().toJson(src);
+    }
+
+    @Override
+    public <T> String serializeOnlyFilter(Object src, Boolean notused,
+            String... filterAttr) throws Exception {
+        return  gson
+                .addSerializationExclusionStrategy(
+                        include(null,filterAttr)).create().toJson(src);
+    }
 
     @Override
     public <T> String serializeOnlyFilter(Object src, Class<T> filterClass,
@@ -157,6 +172,22 @@ public class GSONBuilderService extends
     }
     
     @Override
+    public <T> String serializeAllExceptFilter(Object src, String... 
filterAttr)
+            throws Exception {
+        return gson
+                .addSerializationExclusionStrategy(
+                        exclude(null, filterAttr)).create().toJson(src);
+    }
+
+    @Override
+    public <T> String serializeAllExceptFilter(Object src, Boolean notused,
+            String... filterAttr) throws Exception {
+        return gson
+                .addSerializationExclusionStrategy(
+                        exclude(null, filterAttr)).create().toJson(src);
+    }
+    
+    @Override
     public String ser(Object src, Boolean refreshCache) throws Exception {
         throw new Exception("Not implemented!");
     }
@@ -338,6 +369,4 @@ public class GSONBuilderService extends
         }.init(clazz, filterAttrs);
     }
 
-    
-
 }

Modified: 
turbine/fulcrum/trunk/json/gson/src/test/org/apache/fulcrum/json/gson/DefaultServiceTest.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/gson/src/test/org/apache/fulcrum/json/gson/DefaultServiceTest.java?rev=1677013&r1=1677012&r2=1677013&view=diff
==============================================================================
--- 
turbine/fulcrum/trunk/json/gson/src/test/org/apache/fulcrum/json/gson/DefaultServiceTest.java
 (original)
+++ 
turbine/fulcrum/trunk/json/gson/src/test/org/apache/fulcrum/json/gson/DefaultServiceTest.java
 Thu Apr 30 15:20:06 2015
@@ -69,7 +69,7 @@ public class DefaultServiceTest extends
 
     public void testSerializeExcludeNothing() throws Exception {
         String serJson = sc.serializeAllExceptFilter(new TestClass("mytest"),
-                (Class) null, (String[]) null);
+                (String[]) null);
         assertEquals(
                 "Serialization failed ",
                 
"{\"container\":{\"cf\":\"Config.xml\"},\"configurationName\":\"Config.xml\",\"name\":\"mytest\"}",
@@ -98,7 +98,7 @@ public class DefaultServiceTest extends
     public void testSerializeExcludeField() throws Exception {
 
         String serJson = sc.serializeAllExceptFilter(new TestClass("mytest"),
-                (Class) null, "configurationName");
+                 "configurationName");
         assertEquals("Serialization failed ",
                 "{\"container\":{\"cf\":\"Config.xml\"},\"name\":\"mytest\"}",
                 serJson);
@@ -238,7 +238,7 @@ public class DefaultServiceTest extends
         // as gson adds we could not use multiple disjunct exclusion strategies
         Rectangle filteredRectangle = new Rectangle(5, 10);
         filteredRectangle.setName("jim");
-        String rectangle = sc.serializeOnlyFilter(filteredRectangle, (Class) 
null, "w");
+        String rectangle = sc.serializeOnlyFilter(filteredRectangle, "w");
         assertEquals(
                 "Ser filtered Rectangle failed ",
                 "{\"w\":5}",

Modified: turbine/fulcrum/trunk/json/jackson/pom.xml
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/jackson/pom.xml?rev=1677013&r1=1677012&r2=1677013&view=diff
==============================================================================
--- turbine/fulcrum/trunk/json/jackson/pom.xml (original)
+++ turbine/fulcrum/trunk/json/jackson/pom.xml Thu Apr 30 15:20:06 2015
@@ -84,18 +84,6 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>3.8.1</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.fulcrum</groupId>
-            <artifactId>fulcrum-testcontainer</artifactId>
-            <version>1.0.6</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
             <groupId>org.apache.fulcrum</groupId>
             <artifactId>fulcrum-yaafi</artifactId>
             <version>1.0.6</version>

Modified: 
turbine/fulcrum/trunk/json/jackson/src/java/org/apache/fulcrum/json/jackson/JacksonMapperService.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/jackson/src/java/org/apache/fulcrum/json/jackson/JacksonMapperService.java?rev=1677013&r1=1677012&r2=1677013&view=diff
==============================================================================
--- 
turbine/fulcrum/trunk/json/jackson/src/java/org/apache/fulcrum/json/jackson/JacksonMapperService.java
 (original)
+++ 
turbine/fulcrum/trunk/json/jackson/src/java/org/apache/fulcrum/json/jackson/JacksonMapperService.java
 Thu Apr 30 15:20:06 2015
@@ -163,11 +163,23 @@ public class JacksonMapperService extend
         return mapper.readValue(json, mapper.getTypeFactory()
                 .constructCollectionType(collectionType, type));
     }
+    
+    @Override
+    public <T> String serializeAllExceptFilter(Object src, String... 
filterAttr)
+            throws Exception {
+        return serializeAllExceptFilter(src, src.getClass(), true, filterAttr);
+    }
+
+    @Override
+    public <T> String serializeAllExceptFilter(Object src, Boolean refresh,
+            String... filterAttr) throws Exception {
+        return serializeAllExceptFilter(src, src.getClass(), refresh, 
filterAttr);
+    }
 
     @Override
     public synchronized <T> String serializeAllExceptFilter(Object src,
             Class<T> filterClass, String... filterAttr) throws Exception {
-        return serializeAllExceptFilter(src, filterClass, false, filterAttr);
+        return serializeAllExceptFilter(src, filterClass, true, filterAttr);
     }
     
     @Override
@@ -178,7 +190,7 @@ public class JacksonMapperService extend
         FilterProvider filter = null;
         if ( filterClass != null) {
             if (filterAttr != null && filterAttr.length > 0 && 
-                            !this.filters.containsKey(filterClass.getName())) {
+                    (refreshFilter || 
!this.filters.containsKey(filterClass.getName()))) {
                 filter = new SimpleFilterProvider().addFilter(
                         filterClass.getName(),
                         
SimpleBeanPropertyFilter.serializeAllExcept(filterAttr));
@@ -194,11 +206,24 @@ public class JacksonMapperService extend
         }
         return serialized;
     }
+    
+
+    @Override
+    public <T> String serializeOnlyFilter(Object src, String... filterAttr)
+            throws Exception {
+        return serializeOnlyFilter(src, src.getClass(), true, filterAttr);
+    }
+
+    @Override
+    public <T> String serializeOnlyFilter(Object src, Boolean refresh,
+            String... filterAttr) throws Exception {
+        return serializeOnlyFilter(src, src.getClass(), refresh, filterAttr);
+    }
 
     @Override
     public synchronized <T> String serializeOnlyFilter(Object src,
             Class<T> filterClass, String... filterAttr) throws Exception {
-        return serializeOnlyFilter(src, filterClass, false, filterAttr);
+        return serializeOnlyFilter(src, filterClass, true, filterAttr);
     }
     
     @Override
@@ -491,5 +516,4 @@ public class JacksonMapperService extend
         }
     }
 
-
 }

Modified: 
turbine/fulcrum/trunk/json/jackson/src/test/org/apache/fulcrum/json/jackson/DefaultServiceTest.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/jackson/src/test/org/apache/fulcrum/json/jackson/DefaultServiceTest.java?rev=1677013&r1=1677012&r2=1677013&view=diff
==============================================================================
--- 
turbine/fulcrum/trunk/json/jackson/src/test/org/apache/fulcrum/json/jackson/DefaultServiceTest.java
 (original)
+++ 
turbine/fulcrum/trunk/json/jackson/src/test/org/apache/fulcrum/json/jackson/DefaultServiceTest.java
 Thu Apr 30 15:20:06 2015
@@ -63,8 +63,7 @@ public class DefaultServiceTest extends
     }
 
     public void testSerializeExcludeNothing() throws Exception {
-        String serJson = sc.serializeAllExceptFilter(new TestClass("mytest"),
-                (Class) null, (String[]) null);
+        String serJson = sc.ser(new TestClass("mytest"));
         assertEquals(
                 "Serialization failed ",
                 
"{\"container\":{\"cf\":\"Config.xml\"},\"configurationName\":\"Config.xml\",\"name\":\"mytest\"}",

Modified: turbine/fulcrum/trunk/json/jackson2/pom.xml
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/jackson2/pom.xml?rev=1677013&r1=1677012&r2=1677013&view=diff
==============================================================================
--- turbine/fulcrum/trunk/json/jackson2/pom.xml (original)
+++ turbine/fulcrum/trunk/json/jackson2/pom.xml Thu Apr 30 15:20:06 2015
@@ -84,18 +84,6 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>3.8.1</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.fulcrum</groupId>
-            <artifactId>fulcrum-testcontainer</artifactId>
-            <version>1.0.6</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
             <groupId>org.apache.fulcrum</groupId>
             <artifactId>fulcrum-yaafi</artifactId>
             <version>1.0.6</version>

Added: 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/CacheService.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/CacheService.java?rev=1677013&view=auto
==============================================================================
--- 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/CacheService.java
 (added)
+++ 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/CacheService.java
 Thu Apr 30 15:20:06 2015
@@ -0,0 +1,69 @@
+package org.apache.fulcrum.json.jackson;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import com.fasterxml.jackson.databind.AnnotationIntrospector;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;
+import com.fasterxml.jackson.databind.ser.FilterProvider;
+import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
+
+public class CacheService {
+
+    AnnotationIntrospector primary;
+    Map<String, FilterProvider> filters =  new ConcurrentHashMap<String, 
FilterProvider>();;
+    
+    public CacheService(AnnotationIntrospector primary) {
+        this.primary = primary;
+    }
+
+    <T> void removeFilter(Class<T> filterClass, Boolean excludeType) {
+        if (filterClass == null)
+            return;
+        if (filters.containsKey(filterClass.getName())) {
+            removeCustomIntrospectorWithExternalFilterId(filterClass, 
excludeType);
+            SimpleFilterProvider smpfilter = (SimpleFilterProvider) filters
+                    .get(filterClass.getName());
+            smpfilter.removeFilter(filterClass.getName());
+            filters.remove(filterClass.getName());
+        }
+    }
+    
+    <T> void removeCustomIntrospectorWithExternalFilterId(
+            Class<T> externalFilterId, Boolean excludeType) {
+        if (primary instanceof SimpleNameIntrospector) {
+            if (externalFilterId != null) {
+                ((SimpleNameIntrospector) primary)
+                        .removeExternalFilterClass(externalFilterId);
+                if (excludeType) {
+                    ((SimpleNameIntrospector) primary)
+                    .removeExternalFilterExcludeClass(externalFilterId);
+                }
+            }
+        }
+    }
+
+    void cleanSerializerCache(ObjectMapper mapper) {
+        if (mapper.getSerializerProvider() instanceof 
DefaultSerializerProvider) {
+            int cachedSerProvs = ((DefaultSerializerProvider) mapper
+                    .getSerializerProvider()).cachedSerializersCount();
+            if (cachedSerProvs > 0) {
+//                getLogger()
+//                        .debug("flushing cachedSerializersCount:"
+//                                + cachedSerProvs);
+                ((DefaultSerializerProvider) mapper.getSerializerProvider())
+                        .flushCachedSerializers();
+            }
+        }
+    }
+
+    public Map<String, FilterProvider> getFilters() {
+        return filters;
+    }
+
+    public void setFilters(Map<String, FilterProvider> filters) {
+        this.filters = filters;
+    }
+
+}

Propchange: 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/CacheService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/CustomModule.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/CustomModule.java?rev=1677013&view=auto
==============================================================================
--- 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/CustomModule.java
 (added)
+++ 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/CustomModule.java
 Thu Apr 30 15:20:06 2015
@@ -0,0 +1,18 @@
+package org.apache.fulcrum.json.jackson;
+
+import com.fasterxml.jackson.core.Version;
+import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+
+public final class CustomModule<T> extends SimpleModule {
+
+    private static final long serialVersionUID = 1L;
+
+    public CustomModule(String name, Class<T> targetClazz,
+            StdSerializer<T> stdSer, StdDeserializer<T> stdDeser) {
+        super(name, Version.unknownVersion());
+        addSerializer(targetClazz, stdSer);
+        addDeserializer(targetClazz, stdDeser);
+    }
+}

Propchange: 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/CustomModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/Jackson2MapperService.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/Jackson2MapperService.java?rev=1677013&r1=1677012&r2=1677013&view=diff
==============================================================================
--- 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/Jackson2MapperService.java
 (original)
+++ 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/Jackson2MapperService.java
 Thu Apr 30 15:20:06 2015
@@ -25,8 +25,6 @@ import java.text.SimpleDateFormat;
 import java.util.Collection;
 import java.util.Enumeration;
 import java.util.Hashtable;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.avalon.framework.activity.Initializable;
 import org.apache.avalon.framework.configuration.Configurable;
@@ -40,7 +38,6 @@ import com.fasterxml.jackson.core.JsonGe
 import com.fasterxml.jackson.core.JsonParser;
 import com.fasterxml.jackson.core.JsonParser.Feature;
 import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.core.Version;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.AnnotationIntrospector;
 import com.fasterxml.jackson.databind.DeserializationFeature;
@@ -54,16 +51,13 @@ import com.fasterxml.jackson.databind.Ob
 import com.fasterxml.jackson.databind.SerializationFeature;
 import com.fasterxml.jackson.databind.SerializerProvider;
 import com.fasterxml.jackson.databind.cfg.ConfigFeature;
-import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
 import com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair;
 import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
 import com.fasterxml.jackson.databind.module.SimpleModule;
-import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;
 import com.fasterxml.jackson.databind.ser.FilterProvider;
 import com.fasterxml.jackson.databind.ser.PropertyFilter;
 import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
 import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
-import com.fasterxml.jackson.databind.ser.std.StdSerializer;
 
 /**
  * 
@@ -98,7 +92,6 @@ public class Jackson2MapperService exten
     private Hashtable<String, Boolean> features = null;
     private Hashtable<String, String> featureTypes = null;
 
-    private Map<String, FilterProvider> filters;
     private String dateFormat;
 
     /**
@@ -110,6 +103,7 @@ public class Jackson2MapperService exten
     public boolean cacheFilters = true; // true -> this is by default true in 
jackson, if not using
                                         // multiple serialization in one thread
     String[] defaultTypeDefs = null;
+    private CacheService cacheService;
 
     @Override
     public String ser(Object src) throws Exception {
@@ -136,9 +130,10 @@ public class Jackson2MapperService exten
             return ser(src);
         }    
         getLogger().debug("ser class::" + src.getClass() + " with filter " + 
filter);
+        mapper.setFilters(filter);
         String res =  mapper.writer(filter).writeValueAsString(src);
         if (cleanCache) {
-            cleanSerializerCache();
+            cacheService.cleanSerializerCache(mapper);
         }
         return res;
     }
@@ -164,7 +159,7 @@ public class Jackson2MapperService exten
             throws Exception {
         String res =  
mapper.writerWithType(collectionType).writeValueAsString(src);
         if (cleanCache) {
-            cleanSerializerCache();
+            cacheService.cleanSerializerCache(mapper);
         }
         return res;
     }
@@ -180,13 +175,11 @@ public class Jackson2MapperService exten
         }
     }
     
-    
     public <T> Collection<T> deSerCollectionWithTypeReference(String json,
             TypeReference collectionType ) throws Exception {
             return mapper.readValue(json, collectionType);
     }
 
-
     public void getJsonService() throws InstantiationException {
     }
 
@@ -210,9 +203,9 @@ public class Jackson2MapperService exten
     /**
      * Add a named module
      * 
-     * @param name name of the module
+     * @param name Name of the module
      * 
-     * @param target target class
+     * @param target Target class
      * 
      * @param module
      *            Either an Jackson Module @link {@link Module} or an custom
@@ -248,30 +241,68 @@ public class Jackson2MapperService exten
     }
     
     @Override
+    public <T> String serializeAllExceptFilter(Object src, String... 
filterAttr)
+            throws Exception {
+        return serializeAllExceptFilter(src, src.getClass(), true, filterAttr);
+    }
+    
+    public synchronized <T> String serializeAllExceptFilter(Object src, 
Boolean cache, String... filterAttr) throws Exception {
+        return serializeAllExceptFilter(src, src.getClass(), cache, 
filterAttr);
+    }
+    
+    public synchronized <T> String serializeAllExceptFilter(Object src,
+            Class<T>[] filterClasses, String... filterAttr) throws Exception {
+        return serializeAllExceptFilter(src, filterClasses, true, filterAttr);
+    }
+    
+    @Override
     public synchronized <T> String serializeAllExceptFilter(Object src,
             Class<T> filterClass, String... filterAttr) throws Exception {
-        return serializeAllExceptFilter(src, filterClass, false, filterAttr);
+        return serializeAllExceptFilter(src, filterClass, true, filterAttr);
     }
-
+    
+    @Override
+    public <T> String serializeAllExceptFilter(Object src,
+            Class<T> filterClass, Boolean cleanFilter, String... filterAttr)
+            throws Exception {
+        return serializeAllExceptFilter(src, new Class[] {filterClass}, 
cleanFilter, filterAttr);
+    }
+    
     public synchronized <T> String serializeAllExceptFilter(Object src,
-            Class<T> filterClass, Boolean clean, String... filterAttr) throws 
Exception {
+            Class<T>[] filterClasses, Boolean clean, String... filterAttr) 
throws Exception {
         PropertyFilter pf = null;
         if (filterAttr != null)
             pf = SimpleBeanPropertyFilter.serializeAllExcept(filterAttr);
         else 
             pf = SimpleBeanPropertyFilter.serializeAllExcept("dummy");
-        return filter(src, filterClass, pf, clean, true);
+        return filter(src, filterClasses, pf, clean, true);
+    }
+    
+    @Override
+    public <T> String serializeOnlyFilter(Object src, String... filterAttrs)
+            throws Exception {
+        return serializeOnlyFilter(src, src.getClass(), true, filterAttrs);
+    }
+    
+    public synchronized <T> String serializeOnlyFilter(Object src,
+             Boolean cache, String... filterAttr) throws Exception {
+        return serializeOnlyFilter(src, src.getClass(), cache, filterAttr);
     }
     
     @Override
     public synchronized <T> String serializeOnlyFilter(Object src,
             Class<T> filterClass,  String... filterAttr) throws Exception {
-        return serializeOnlyFilter(src, filterClass, false, filterAttr);
+        return serializeOnlyFilter(src, filterClass, true, filterAttr);
     }
 
     @Override
     public synchronized <T> String serializeOnlyFilter(Object src,
             Class<T> filterClass, Boolean refresh, String... filterAttr) 
throws Exception {
+        return serializeOnlyFilter(src, new Class[]{ filterClass }, refresh, 
filterAttr);
+    }
+    
+    public synchronized <T> String serializeOnlyFilter(Object src,
+            Class<T>[] filterClasses, Boolean refresh, String... filterAttr) 
throws Exception {
         PropertyFilter pf = null;
         if (filterAttr != null && filterAttr.length > 0) {
             pf = SimpleBeanPropertyFilter.filterOutAllExcept(filterAttr);
@@ -279,25 +310,25 @@ public class Jackson2MapperService exten
         } else {
             pf = SimpleBeanPropertyFilter.filterOutAllExcept("dummy");
         }
-        return filter(src, filterClass, pf, refresh, false);
+        return filter(src, filterClasses, pf, refresh, false);
     }
     
     @Override
     public String ser(Object src, Boolean cleanCache) throws Exception {
-        if (filters.containsKey(src.getClass().getName())) {
+        if (cacheService.getFilters().containsKey(src.getClass().getName())) {
             getLogger().warn(
                     "Found registered filter - using instead of default view 
filter for class:"
                             + src.getClass().getName());
             // throw new
             // Exception("Found registered filter - could not use custom view 
and custom filter for class:"+
             // src.getClass().getName());
-            SimpleFilterProvider filter = (SimpleFilterProvider) 
this.filters.get(src.getClass()
+            SimpleFilterProvider filter = (SimpleFilterProvider) 
cacheService.getFilters().get(src.getClass()
                     .getName());
             return ser(src, filter, 
cleanCache);//mapper.writerWithView(src.getClass()).writeValueAsString(src);
         }
         String res = 
mapper.writerWithView(Object.class).writeValueAsString(src);
         if (cleanCache != null && cleanCache) {
-            cleanSerializerCache();
+            cacheService.cleanSerializerCache(mapper);
         }
         return res;
     }
@@ -306,70 +337,87 @@ public class Jackson2MapperService exten
     public <T> String ser(Object src, Class<T> type, Boolean cleanCache)
             throws Exception {
         getLogger().info("serializing object:" + src + " for type "+ type);
-        if (src != null && filters.containsKey(src.getClass().getName())) {
+        if (src != null && 
cacheService.getFilters().containsKey(src.getClass().getName())) {
             getLogger()
                     .warn("Found registered filter - could not use custom view 
and custom filter for class:"
                             + src.getClass().getName());
             // throw new
             // Exception("Found registered filter - could not use custom view 
and custom filter for class:"+
             // src.getClass().getName());
-            SimpleFilterProvider filter = (SimpleFilterProvider) 
this.filters.get(src.getClass()
+            SimpleFilterProvider filter = (SimpleFilterProvider) 
cacheService.getFilters().get(src.getClass()
                     .getName());
             return ser(src, filter);
         }
 
         String res = (type != null)? 
mapper.writerWithView(type).writeValueAsString(src): 
mapper.writeValueAsString(src);
         if (cleanCache) {
-            cleanSerializerCache();
+            cacheService.cleanSerializerCache(mapper);
         }
         return res;
     }  
 
-    private <T> String filter(Object src, Class<T> filterClass,
+    /**
+     * 
+     * @param src The source Object to be filtered.
+     * @param filterClass Explicit class as a class filter, which is only used 
as a filter in {@link #serializeAllExceptFilter(Object, Class, String...)}. In 
all other cases this is set to src objects´s source class to become the key in 
the filter object cache.
+     * This is because, no use case was found to include just one class in a 
filter, e.g. in @link {@link #serializeOnlyFilter(Object, Class, Boolean, 
String...)}, i.e. just serializing only a provided filter class. 
+     * @param pf Expecting a property filter from e.g @link {@link 
SimpleBeanPropertyFilter}.
+     * @param clean if <code>true</code> does not reuse the filter object (no 
cashing).
+     * @param excludeType Is set to  <code>true</code> in {@link 
#serializeAllExceptFilter(Object, Class, String...)}, otherweise 
<code>false</code>.  
+     * @return The Serialized Object as String 
+     * @throws Exception
+     */
+    private <T> String filter(Object src, Class<T>[] filterClasses,
             PropertyFilter pf,  Boolean clean, Boolean excludeType) throws 
Exception {
         FilterProvider filter = null;
         if (src != null) {
-            filter = checkFilter(pf, src.getClass(), filterClass, excludeType);
+            filter = checkFilter(pf, src.getClass(), filterClasses, 
excludeType);
         }
         getLogger().info("filtering with filter "+ filter);
         String serialized = ser(src, filter, clean);
         if (!cacheFilters || clean) {
-            removeFilter(filterClass, excludeType);
-            if (src != null) removeFilter(src.getClass(), excludeType);
+            if (src != null) {
+                cacheService.removeFilter(src.getClass(), excludeType);
+            } else if (filterClasses.length >0) {
+                cacheService.removeFilter(filterClasses[0], excludeType);
+            }
         }
         return serialized;
     }
 
     @SuppressWarnings("unchecked")
     private <T> FilterProvider checkFilter(PropertyFilter pf,
-            Class rootFilterClass, Class<T> filterClass,  Boolean excludeType) 
{
+            Class rootFilterClass, Class<T>[] filterClasses,  Boolean 
excludeType) {
         SimpleFilterProvider filter = null;
-        if ( (filterClass == null || !rootFilterClass.equals(filterClass))) {
-            // filter attributes in root class
-            filter = retrieveFilter(pf, rootFilterClass, excludeType);
-        }
-        if (filterClass != null) {
-            filter = retrieveFilter(pf, filterClass, excludeType);
+        if (filterClasses == null ) {
+            filter = retrieveFilter(pf, new Class[]{ rootFilterClass }, 
excludeType);
+        } else {
+            if (filterClasses.length > 0 && 
!rootFilterClass.equals(filterClasses[0])) {
+                filter = retrieveFilter(pf,  rootFilterClass, filterClasses, 
excludeType );
+            } else {
+                filter = retrieveFilter(pf, filterClasses, excludeType);
+            }
         }
         return filter;
     }
-
-    private <T> SimpleFilterProvider retrieveFilter(PropertyFilter pf, 
Class<T> filterClass, Boolean excludeType ) {
+    
+    private <T> SimpleFilterProvider retrieveFilter(PropertyFilter pf, 
Class<T> cachefilterClass, Class<T>[] filterClasses, Boolean excludeType ) {
         SimpleFilterProvider filter = null;
         if (pf != null) {
             filter = new SimpleFilterProvider();
             filter.setDefaultFilter(pf);
         }
-        if (!this.filters.containsKey(filterClass.getName())) {
-            getLogger().debug("add filter for class " + filterClass.getName());
-            //filter.addFilter(filterClass.getName(), pf);
-            setCustomIntrospectorWithExternalFilterId(filterClass, 
excludeType); // filter
-                                                                    // class
+        if 
(!cacheService.getFilters().containsKey(cachefilterClass.getName())) {
+            getLogger().debug("add filter for cache filter Class " + 
cachefilterClass.getName());
+            if (filterClasses != null && filterClasses.length > 0 && 
filterClasses[0] != null) {
+                getLogger().debug("filter classes l:" + filterClasses.length + 
" first el:"+ filterClasses[0]);
+                setCustomIntrospectorWithExternalFilterId(filterClasses, 
excludeType); // filter class
+            }
             if (pf != null)  {
-                this.filters.put(filterClass.getName(), (FilterProvider) 
filter);    
+                cacheService.getFilters().put(cachefilterClass.getName(), 
(FilterProvider) filter);    
             } 
         } else {
-            filter = (SimpleFilterProvider) this.filters.get(filterClass
+            filter = 
(SimpleFilterProvider)cacheService.getFilters().get(cachefilterClass
                     .getName());
             //setCustomIntrospectorWithExternalFilterId(filterClass); // filter
             // class
@@ -378,77 +426,39 @@ public class Jackson2MapperService exten
         return filter; 
     }
 
-    private <T> void removeFilter(Class<T> filterClass, Boolean excludeType) {
-        if (filterClass == null)
-            return;
-        if (this.filters.containsKey(filterClass.getName())) {
-            removeCustomIntrospectorWithExternalFilterId(filterClass, 
excludeType);
-            SimpleFilterProvider smpfilter = (SimpleFilterProvider) 
this.filters
-                    .get(filterClass.getName());
-            smpfilter.removeFilter(filterClass.getName());
-            this.filters.remove(filterClass.getName());
-            getLogger().debug(
-                    "removed from  SimpleFilterProvider filters "
-                            + filterClass.getName());
-        }
-    }
-    
-    private void cleanSerializerCache() {
-        if (mapper.getSerializerProvider() instanceof 
DefaultSerializerProvider) {
-            int cachedSerProvs = ((DefaultSerializerProvider) mapper
-                    .getSerializerProvider()).cachedSerializersCount();
-            if (cachedSerProvs > 0) {
-                getLogger()
-                        .debug("flushing cachedSerializersCount:"
-                                + cachedSerProvs);
-                ((DefaultSerializerProvider) mapper.getSerializerProvider())
-                        .flushCachedSerializers();
-            }
-        }
+    private <T> SimpleFilterProvider retrieveFilter(PropertyFilter pf, 
Class<T>[] filterClasses, Boolean excludeType ) {
+        return  retrieveFilter(pf,  filterClasses[0], filterClasses, 
excludeType );
     }
 
     private <T> void setCustomIntrospectorWithExternalFilterId(
-            Class<T> externalFilterId, boolean exludeType) {
+            Class<T>[] externalFilterIds, boolean excludeType) {
         if (primary instanceof SimpleNameIntrospector) {
-            if (externalFilterId != null) {
-                if (exludeType) {
+            if (externalFilterIds != null) {
+                ((SimpleNameIntrospector) 
primary).setIsExludeType(excludeType);
+                if (excludeType) {
+                    // first one is required that we get to the PropertyFilter 
                     ((SimpleNameIntrospector) primary)
-                    .setExternalFilterClasses(externalFilterId);
+                    .setExternalFilterClasses(externalFilterIds);
             getLogger()
                     .debug("added class for filters "
-                            + externalFilterId.getName());
+                            + externalFilterIds);
             ((SimpleNameIntrospector) primary)
-            .setExternalFilterExcludeClasses(externalFilterId);
+            .setExternalFilterExcludeClasses(externalFilterIds);
     getLogger()
             .debug("added exclude class for filters "
-                    + externalFilterId.getName());
+                    + externalFilterIds);
                 } else {
                     ((SimpleNameIntrospector) primary)
-                    .setExternalFilterClasses(externalFilterId);
+                    .setExternalFilterClasses(externalFilterIds);
             getLogger()
                     .debug("added class for filters "
-                            + externalFilterId.getName());                    
-                }
-
-            }
-        }
-    }
-
-    private <T> void removeCustomIntrospectorWithExternalFilterId(
-            Class<T> externalFilterId, Boolean excludeType) {
-        if (primary instanceof SimpleNameIntrospector) {
-            if (externalFilterId != null) {
-                ((SimpleNameIntrospector) primary)
-                        .removeExternalFilterClass(externalFilterId);
-                getLogger().debug(
-                        "removed from introspector filter id  "
-                                + externalFilterId.getName());
-                if (excludeType) {
-                    ((SimpleNameIntrospector) primary)
-                    .removeExternalFilterExcludeClass(externalFilterId);
-            getLogger().debug(
-                    "removed from exclude class list  "
-                            + externalFilterId.getName());
+                            + externalFilterIds);
+            // too cumbersome
+//                ((SimpleNameIntrospector) primary)
+//                .setExternalFilterIncludeClasses(externalFilterId);
+//        getLogger()
+//                .debug("added include class for filters "
+//                        + externalFilterId.getName());
                 }
             }
         }
@@ -694,7 +704,6 @@ public class Jackson2MapperService exten
 
         mapper.setDateFormat(new SimpleDateFormat(dateFormat));
 
-        filters = new ConcurrentHashMap<String, FilterProvider>();
         getLogger().debug("initialized mapper:" + mapper);
 
         mapper.getSerializerProvider().setNullValueSerializer(
@@ -708,6 +717,7 @@ public class Jackson2MapperService exten
 
                     }
                 });
+        cacheService = new CacheService(primary);
     }
 
     public ObjectMapper getMapper() {
@@ -718,38 +728,6 @@ public class Jackson2MapperService exten
         this.mapper = mapper;
     }
 
-    public static final class MixinModule extends SimpleModule {
-        /**
-         * 
-         */
-        private static final long serialVersionUID = 1L;
-        public final Class<?> clazz;
-        public final Class<?> mixin;
-
-        public MixinModule(String name, Class clazz, Class mixin) {
-            super(name, Version.unknownVersion());
-            this.clazz = clazz;
-            this.mixin = mixin;
-        }
-
-        @Override
-        public void setupModule(SetupContext context) {
-            context.setMixInAnnotations(this.clazz, this.mixin);
-        }
-    }
-
-    public static final class CustomModule<T> extends SimpleModule {
-
-        private static final long serialVersionUID = 1L;
-
-        public CustomModule(String name, Class<T> targetClazz,
-                StdSerializer<T> stdSer, StdDeserializer<T> stdDeser) {
-            super(name, Version.unknownVersion());
-            addSerializer(targetClazz, stdSer);
-            addDeserializer(targetClazz, stdDeser);
-        }
-    }
-
     public boolean isCacheFilters() {
         return cacheFilters;
     }

Added: 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/MixinModule.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/MixinModule.java?rev=1677013&view=auto
==============================================================================
--- 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/MixinModule.java
 (added)
+++ 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/MixinModule.java
 Thu Apr 30 15:20:06 2015
@@ -0,0 +1,24 @@
+package org.apache.fulcrum.json.jackson;
+
+import com.fasterxml.jackson.core.Version;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+
+public final class MixinModule extends SimpleModule {
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 1L;
+    public final Class<?> clazz;
+    public final Class<?> mixin;
+
+    public MixinModule(String name, Class clazz, Class mixin) {
+        super(name, Version.unknownVersion());
+        this.clazz = clazz;
+        this.mixin = mixin;
+    }
+
+    @Override
+    public void setupModule(SetupContext context) {
+        context.setMixInAnnotations(this.clazz, this.mixin);
+    }
+}
\ No newline at end of file

Propchange: 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/MixinModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/SimpleNameIntrospector.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/SimpleNameIntrospector.java?rev=1677013&r1=1677012&r2=1677013&view=diff
==============================================================================
--- 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/SimpleNameIntrospector.java
 (original)
+++ 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/SimpleNameIntrospector.java
 Thu Apr 30 15:20:06 2015
@@ -21,6 +21,7 @@ package org.apache.fulcrum.json.jackson;
 
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import com.fasterxml.jackson.databind.introspect.Annotated;
 import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
@@ -30,7 +31,8 @@ import com.fasterxml.jackson.databind.se
 /**
  * The intent of this custom introspector is to provide filtering capabilities
  * by using String parameters (properties and class types), which could be
- * adjusted e.g. from a scriptable context (velocity template).
+ * adjusted e.g. from a scriptable context (velocity template). 
+ * Class Type Filtering currently not supported except for Exclude Filter: 
{@link Jackson2MapperService#serializeAllExceptFilter(Object, Class, Boolean, 
String...)}.
  * 
  * 
  * @author gk
@@ -42,20 +44,35 @@ public class SimpleNameIntrospector exte
      * 
      */
     private static final long serialVersionUID = 1L;
-    public List<String> externalFilterClasses = new 
CopyOnWriteArrayList<String>();
-    public List<String> externalFilterExcludeClasses = new 
CopyOnWriteArrayList<String>();
+    private List<String> externalFilterClasses = new 
CopyOnWriteArrayList<String>();
+    private List<String> externalFilterExcludeClasses = new 
CopyOnWriteArrayList<String>();
+    private List<String> externalFilterIncludeClasses = new 
CopyOnWriteArrayList<String>();
+    private AtomicBoolean isExludeType = new AtomicBoolean(false);
 
     /**
-     * Filtering on method types, cft. @link 
+     * Filtering on method types.
      * 
      */
     @Override
     public Boolean isIgnorableType(AnnotatedClass ac) {
         Boolean isIgnorable = super.isIgnorableType(ac);
         if (isIgnorable == null || !isIgnorable) {
-            if (!externalFilterExcludeClasses.isEmpty()
-                    && externalFilterExcludeClasses.contains(ac.getName())) {
-                isIgnorable = true;
+            if (getIsExludeType()) { // could be removed, if cleaning after 
call ?
+                if (!externalFilterExcludeClasses.isEmpty()
+                        && 
externalFilterExcludeClasses.contains(ac.getName())) {
+                    isIgnorable = true;
+                }
+            } else {
+                // not yet used
+                if (!externalFilterIncludeClasses.isEmpty()
+                        && 
!externalFilterIncludeClasses.contains(ac.getName())) {
+                        try {
+                            Class.forName(ac.getName());
+                            isIgnorable = true;
+                        } catch (ClassNotFoundException e) {
+                            // no clazz ignore, could NOT ignore as no 
filterable clazz
+                        }
+                }
             }
         }
         return isIgnorable;
@@ -67,8 +84,9 @@ public class SimpleNameIntrospector exte
      */
     @Override
     public Object findFilterId(Annotated ac) {
-        // Let's default to current behavior if annotation is found:
         Object id = super.findFilterId(ac);
+        // Let's default to current behavior if annotation is found:
+        //Object id = super.findFilterId(ac);
         // but use simple class name if not
         if (id == null) {
             String name = ac.getName();
@@ -120,6 +138,29 @@ public class SimpleNameIntrospector exte
         if 
(externalFilterExcludeClasses.contains(externalFilterClass.getName())) {
             externalFilterExcludeClasses.remove(externalFilterClass.getName());
         }
-}
+    }
+    
+    public void setExternalFilterIncludeClasses(Class... classes) {
+
+        for (int i = 0; i < classes.length; i++) {
+            if (!externalFilterIncludeClasses.contains(classes[i].getName())) {
+
+                externalFilterIncludeClasses.add(classes[i].getName());
+            }
+        }
+    }
+    
+    public void removeExternalFilterIncludeClasses(Class externalFilterClass) {
+        if 
(externalFilterIncludeClasses.contains(externalFilterClass.getName())) {
+            externalFilterIncludeClasses.remove(externalFilterClass.getName());
+        }
+    }
+    
+    public boolean getIsExludeType() {
+        return isExludeType.get();
+    }
+    public void setIsExludeType(boolean isExludeType) {
+        this.isExludeType.getAndSet(isExludeType);
+    }
 
 }
\ No newline at end of file

Modified: 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/filters/CustomModuleWrapper.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/filters/CustomModuleWrapper.java?rev=1677013&r1=1677012&r2=1677013&view=diff
==============================================================================
--- 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/filters/CustomModuleWrapper.java
 (original)
+++ 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/filters/CustomModuleWrapper.java
 Thu Apr 30 15:20:06 2015
@@ -19,15 +19,14 @@ package org.apache.fulcrum.json.jackson.
  * under the License.
  */
 
-import org.apache.fulcrum.json.jackson.Jackson2MapperService;
-import org.apache.fulcrum.json.jackson.Jackson2MapperService.CustomModule;
+import org.apache.fulcrum.json.jackson.CustomModule;
 
 import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
 import com.fasterxml.jackson.databind.ser.std.StdSerializer;
 
 /**
- * Used by {@link Jackson2MapperService#addAdapter(String, Class, Object)} to 
provide a wrapper module as a helper class
- * for the inner class {@link CustomModule}.
+ * Provides a wrapper module as a helper class for the inner class {@link 
CustomModule}.
+ * 
  * @author gkallidis
  *
  * @param <T>

Modified: 
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/DefaultServiceTest.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/DefaultServiceTest.java?rev=1677013&r1=1677012&r2=1677013&view=diff
==============================================================================
--- 
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/DefaultServiceTest.java
 (original)
+++ 
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/DefaultServiceTest.java
 Thu Apr 30 15:20:06 2015
@@ -65,9 +65,10 @@ public class DefaultServiceTest extends
         assertEquals("Serialization failed ", preDefinedOutput, serJson);
     }
 
+    //@Test
+    // the default test class: one String field, one Map  
     public void testSerializeExcludeNothing() throws Exception {
-        String serJson = sc.serializeAllExceptFilter(new TestClass("mytest"),
-                (Class) null, (String[]) null);
+        String serJson = sc.serializeAllExceptFilter(new TestClass("mytest"), 
(String[]) null);
         assertEquals(
                 "Serialization failed ",
                 
"{\"container\":{\"cf\":\"Config.xml\"},\"configurationName\":\"Config.xml\",\"name\":\"mytest\"}",
@@ -83,21 +84,24 @@ public class DefaultServiceTest extends
     }
 
     public void testSerializeExcludeClassAndField() throws Exception {
-        String serJson = sc.serializeAllExceptFilter(new TestClass("mytest"),
-                String.class, "container");
+        String serJson = 
((Jackson2MapperService)sc).serializeAllExceptFilter(new TestClass("mytest"),
+               new Class[] { TestClass.class, String.class} , "container");
         assertEquals("Serialization failed ", "{}", serJson);
     }
 
+    // adding  expected result to be consistent
     public void testSerializeExcludeClassAndFields() throws Exception {
-        String serJson = sc.serializeAllExceptFilter(new TestClass("mytest"),
-                Map.class, "configurationName", "name");
+        String serJson = 
((Jackson2MapperService)sc).serializeAllExceptFilter(new TestClass("mytest"),
+               new Class[] { Map.class, String.class} , "configurationName", 
"name");
         assertEquals("Serialization failed ", "{}", serJson);
+        serJson = ((Jackson2MapperService)sc).serializeAllExceptFilter(new 
TestClass("mytest"),
+                (Class)null , "configurationName", "name");
+         assertEquals("Serialization failed ", "{}", serJson);
     }
 
     public void testSerializeExcludeField() throws Exception {
 
-        String serJson = sc.serializeAllExceptFilter(new TestClass("mytest"),
-                (Class) null, "configurationName");
+        String serJson = sc.serializeAllExceptFilter(new TestClass("mytest"), 
"configurationName");
         assertEquals("Serialization failed ",
                 "{\"container\":{\"cf\":\"Config.xml\"},\"name\":\"mytest\"}",
                 serJson);
@@ -228,15 +232,36 @@ public class DefaultServiceTest extends
     
     public void testSerializeWithOnlyFilter() throws Exception {
 
-        String serJson = sc.serializeOnlyFilter(new TestClass("mytest"),
-                (Class) null, "configurationName");
+        String serJson = sc.serializeOnlyFilter(new 
TestClass("mytest"),"configurationName");
+        assertEquals("Serialization failed ",
+                "{\"configurationName\":\"Config.xml\"}",
+                serJson); 
+
+        Rectangle filteredRectangle = new Rectangle(5, 10);
+        filteredRectangle.setName("jim");
+        String rectangle = sc.serializeOnlyFilter(filteredRectangle, "w");
+        assertEquals(
+                "Ser filtered Rectangle failed ",
+                "{\"w\":5}",
+                rectangle);
+
+    }
+    
+    public void testSerializeAllExceptaANDWithOnlyFilter2() throws Exception {
+        
+        String serJson = sc.serializeAllExceptFilter(new 
TestClass("mytest"),"configurationName");
+        assertEquals("Serialization failed ",
+                "{\"container\":{\"cf\":\"Config.xml\"},\"name\":\"mytest\"}",
+                serJson);
+
+        serJson = sc.serializeOnlyFilter(new TestClass("mytest"), 
"configurationName");
         assertEquals("Serialization failed ",
                 "{\"configurationName\":\"Config.xml\"}",
                 serJson); 
 
         Rectangle filteredRectangle = new Rectangle(5, 10);
         filteredRectangle.setName("jim");
-        String rectangle = sc.serializeOnlyFilter(filteredRectangle, (Class) 
null, "w");
+        String rectangle = sc.serializeOnlyFilter(filteredRectangle, "w");
         assertEquals(
                 "Ser filtered Rectangle failed ",
                 "{\"w\":5}",
@@ -253,10 +278,11 @@ public class DefaultServiceTest extends
         }
         Class clazz = 
Class.forName("org.apache.fulcrum.json.jackson.TypedRectangle");
         // no type cft. 
https://github.com/FasterXML/jackson-databind/issues/303 !!
-        
assertTrue("[{\"w\":0},{\"w\":1}]".equals(sc.serializeOnlyFilter(rectList, 
clazz, true,"w")));
+        assertEquals("[{\"w\":0},{\"w\":1}]",sc.serializeOnlyFilter(rectList, 
clazz, true,"w"));
         // need mixin in object class!
         sc.addAdapter("Collection Adapter", Object.class, 
TypedRectangle.Mixins.class);
-        
assertTrue("[\"java.util.ArrayList\",[{\"type\":\"org.apache.fulcrum.json.jackson.TypedRectangle\",\"w\":0},{\"type\":\"org.apache.fulcrum.json.jackson.TypedRectangle\",\"w\":1}]]".equals(sc.serializeOnlyFilter(rectList,
 clazz, true, "w")));
+        
assertEquals("[\"java.util.ArrayList\",[{\"type\":\"org.apache.fulcrum.json.jackson.TypedRectangle\",\"w\":0},{\"type\":\"org.apache.fulcrum.json.jackson.TypedRectangle\",\"w\":1}]]",
+                sc.serializeOnlyFilter(rectList, clazz, true, "w"));
     }
     
     public void testSerializeCollectionWithTypedReference() throws Exception {

Modified: 
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JacksonMapperEnabledDefaultTyping_OBJECT_AND_NON_CONCRETE_Test.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JacksonMapperEnabledDefaultTyping_OBJECT_AND_NON_CONCRETE_Test.java?rev=1677013&r1=1677012&r2=1677013&view=diff
==============================================================================
--- 
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JacksonMapperEnabledDefaultTyping_OBJECT_AND_NON_CONCRETE_Test.java
 (original)
+++ 
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JacksonMapperEnabledDefaultTyping_OBJECT_AND_NON_CONCRETE_Test.java
 Thu Apr 30 15:20:06 2015
@@ -120,7 +120,7 @@ public class JacksonMapperEnabledDefault
     public void testSerializeWithCustomFilter() throws Exception {
         Bean filteredBean = new Bean();
         filteredBean.setName("joe");
-        String bean = sc.serializeOnlyFilter(filteredBean, Bean.class, "name");
+        String bean = sc.serializeOnlyFilter(filteredBean, "name");
         assertEquals(
                 "Ser filtered Bean failed ",
                 "{\"name\":\"joe\"}",
@@ -129,7 +129,7 @@ public class JacksonMapperEnabledDefault
         Rectangle filteredRectangle = new Rectangle(5, 10);
         filteredRectangle.setName("jim");
         String rectangle = sc.serializeOnlyFilter(filteredRectangle,
-                Rectangle.class, "w", "name");
+               "w", "name");
         assertEquals("Ser filtered Rectangle failed ",
                 "{\"w\":5,\"name\":\"jim\"}", rectangle);
     }

Modified: 
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JacksonMapperTest.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JacksonMapperTest.java?rev=1677013&r1=1677012&r2=1677013&view=diff
==============================================================================
--- 
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JacksonMapperTest.java
 (original)
+++ 
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JacksonMapperTest.java
 Thu Apr 30 15:20:06 2015
@@ -34,6 +34,9 @@ import org.apache.fulcrum.json.JsonServi
 import org.apache.fulcrum.json.Rectangle;
 import org.apache.fulcrum.json.TestClass;
 import org.apache.fulcrum.testcontainer.BaseUnitTest;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
@@ -60,23 +63,26 @@ public class JacksonMapperTest extends B
         super(testName);
     }
 
+    @Before
     public void setUp() throws Exception {
         super.setUp();
         sc = (JsonService) this.lookup(JsonService.ROLE);
         logger = new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG);
     }
 
+    @Test
     public void testSerialize() throws Exception {
         String serJson = sc.ser(new JacksonMapperTest("mytest"));
         assertEquals("Set failed ", "{\"name\":\"mytest\"}", serJson);
     }
 
+    @Ignore
     public void testDeSerialize() throws Exception {
         String serJson = sc.ser(new TestClass("mytest"));
         Object deson = sc.deSer(serJson, TestClass.class);
         assertEquals("DeSer failed ", TestClass.class, deson.getClass());
     }
-
+    @Test
     public void testSerializeDateWithDefaultDateFormat() throws Exception {
         Map<String, Date> map = new HashMap<String, Date>();
         map.put("date", Calendar.getInstance().getTime());
@@ -84,7 +90,7 @@ public class JacksonMapperTest extends B
         assertTrue("Serialize with Adapater failed ",
                 serJson.matches("\\{\"date\":\"\\d\\d/\\d\\d/\\d{4}\"\\}"));
     }
-
+    @Test
     public void testDeSerializeDate() throws Exception {
         Map<String, Date> map = new HashMap<String, Date>();
         map.put("date", Calendar.getInstance().getTime());
@@ -108,7 +114,7 @@ public class JacksonMapperTest extends B
                 "{\"w\":5,\"name\":\"jim\"}", rectangle);
 
     }
-
+    @Test
     public void testSerializationCollectionWithFilter() throws Exception {
 
         List<Bean> beanList = new ArrayList<Bean>();
@@ -126,6 +132,7 @@ public class JacksonMapperTest extends B
                 result.replace('"', '\''));
     }
 
+    @Test
     public void testDeserializationCollectionWithFilter() throws Exception {
 
         List<Bean> beanList = new ArrayList<Bean>();
@@ -145,6 +152,7 @@ public class JacksonMapperTest extends B
         }
     }
 
+    @Test
     public void testDeserializationUnTypedCollectionWithFilter()
             throws Exception {
 
@@ -171,6 +179,7 @@ public class JacksonMapperTest extends B
 
     }
 
+    @Test
     public void testSerializeWithMixin() throws Exception {
         Rectangle filteredRectangle = new Rectangle(5, 10);
         filteredRectangle.setName("jim");
@@ -193,7 +202,7 @@ public class JacksonMapperTest extends B
         String bean = sc.serializeOnlyFilter(filteredBean, Bean.class, "name");
         assertEquals("Ser filtered Bean failed ", "{\"name\":\"joe\"}", bean);
     }
-
+    @Test
     public void testSerializationCollectionWithMixin() throws Exception {
 
         List<Bean> beanList = new ArrayList<Bean>();
@@ -210,7 +219,7 @@ public class JacksonMapperTest extends B
                 
"[{'name':'joe0'},{'name':'joe1'},{'name':'joe2'},{'name':'joe3'},{'name':'joe4'},{'name':'joe5'},{'name':'joe6'},{'name':'joe7'},{'name':'joe8'},{'name':'joe9'}]",
                 result.replace('"', '\''));
     }
-
+    @Test
     public void testDeSerUnQuotedObject() throws Exception {
         String jsonString = "{name:\"joe\"}";
         Bean result = sc.deSer(jsonString, Bean.class);
@@ -231,7 +240,7 @@ public class JacksonMapperTest extends B
                     .get(i).getSize());
         }
     }
-    
+    @Test
     public void testDeSerializationCollectionWithMixin() throws Exception {
 
         List<Bean> beanList = new ArrayList<Bean>();
@@ -256,7 +265,7 @@ public class JacksonMapperTest extends B
                             "joe" + i));
         }
     }
-
+    @Test
     public void testCollectionWithMixins() throws Exception {
         List<Object> components = new ArrayList<Object>();
         components.add(new Rectangle(25, 3));

Modified: turbine/fulcrum/trunk/json/pom.xml
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/pom.xml?rev=1677013&r1=1677012&r2=1677013&view=diff
==============================================================================
--- turbine/fulcrum/trunk/json/pom.xml (original)
+++ turbine/fulcrum/trunk/json/pom.xml Thu Apr 30 15:20:06 2015
@@ -92,7 +92,21 @@
             </plugin>
         </plugins>
     </build>
-    
+    <dependencies>
+     <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.12</version>
+            <scope>test</scope>
+      </dependency>
+     <dependency>
+            <groupId>org.apache.fulcrum</groupId>
+            <artifactId>fulcrum-testcontainer</artifactId>
+            <version>1.0.7-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+   
      <profiles>
         <profile>
             <id>apache-release</id>


Reply via email to