Author: painter
Date: Mon Nov  5 17:43:51 2018
New Revision: 1845825

URL: http://svn.apache.org/viewvc?rev=1845825&view=rev
Log:
Fix/update javadocs and addressed a couple findbug performance issues in 
Jackson2MapperService

Modified:
    
turbine/fulcrum/trunk/json/api/src/java/org/apache/fulcrum/json/JsonService.java
    turbine/fulcrum/trunk/json/api/src/site/site.xml
    
turbine/fulcrum/trunk/json/gson/src/java/org/apache/fulcrum/json/gson/GSONBuilderService.java
    
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/CustomModule.java
    
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/filters/CustomModuleWrapper.java
    
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/DefaultServiceTest.java

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=1845825&r1=1845824&r2=1845825&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
 Mon Nov  5 17:43:51 2018
@@ -23,8 +23,8 @@ import java.text.DateFormat;
 import java.util.Collection;
 
 /**
- * This class defines custom methods needed to serialize and deserialize and 
helper
- * methods if needed.
+ * This class defines custom methods needed to serialize and deserialize and
+ * helper methods if needed.
  * 
  * Some methods expect a class parameter.
  * 
@@ -37,238 +37,266 @@ import java.util.Collection;
  * @version $Id$
  */
 public interface JsonService {
-    /** Avalon Identifier **/
-    String ROLE = JsonService.class.getName();
-    
-    String SERVICE_NAME = ROLE;
-
-    /**
-     * Serializes a Java object
-     * 
-     * @param src
-     *            the java object to be serialized, not null.
-     * 
-     * @return JSON string
-     * 
-     * @throws Exception
-     *             if JSON serialization fails
-     */
-    String ser(Object src) throws Exception;
-    
-    /**
-     * @param src
-     *              the java object to be serialized, not null.
-     * @param cleanCache a boolean value, not null.
-     *              If <code>true</code>, try to refresh cache after 
serialization
-     * 
-     */
-    String ser(Object src, Boolean cleanCache) throws Exception;
-
-    /**
-     * Serializes a Java object
-     * 
-     * @param src
-     *            The Java object to be serialized
-     * @param type
-     *            the Java Type, which should be used for the provided object .
-     * 
-     * @return JSON string
-     * 
-     * @throws Exception
-     *             If JSON serialization fails
-     */
-    <T> String ser(Object src, Class<T> type) throws Exception;
-    
-    /**
-     * 
-     * @param src
-     * @param type
-     * @param cleanCache  
-     *          If <code>true</code>, try to clean cache after serialization
-     * 
-     * For other attributes @see {@link #ser(Object, Class)}
-     */
-    <T> String ser(Object src, Class<T> type, Boolean cleanCache) throws 
Exception;
-
-    /**
-     * Deserializing a JSON string
-     * 
-     * @param src
-     *            the JSON string to be deserialized
-     * @param type
-     *            the Java Type to be used as a class
-     * 
-     * @return the Java Object
-     * 
-     * @throws Exception
-     *             if JSON deserialization fails
-     */
-    <T> T deSer(String src, Class<T> type) throws Exception;
-    
-    /**
-     * This is to deserialize collections. Depending on the implementation 
either both collectiontype and elementType is needed or 
-     * the elementType will be derived from the typed collectiontype.
-     * 
-     * @param json
-     *          The JSON string to be deserialized
-     * @param collectionType
-     *          It could be just the collection or the typed collection. It 
may then be used to get the type for element type too.
-     *          Cft. implementation tests for more details (GSON). 
-     * @param elementType
-     *          The element type. This is need in any case to assure the 
generic checking.
-     * @return the generated Java Collection.
-     * @throws Exception
-     */
-    <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 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 String serializeOnlyFilter(Object src, Boolean cleanFilter,
-            String... filterAttr) throws Exception;
-
-    /**
-     * @see #serializeOnlyFilter(Object, Class, Boolean, String...).
-     * 
-     * Caching is set to <code>false</code> for this method call.
-     */
-    public <T> String serializeOnlyFilter(Object src, Class<T> filterClass,
-            String... filterAttr) throws Exception;
-    
-    /**
-     * Serialize only object properties where filter attributes are provided. 
If no filter is set, no attributes should be returned.
-     * 
-     * @param src
-     *            The Java object to serialize
-     * @param filterClass
-     *            By default filterClass is a) the class to be filtered 
(required for filtering list elements) b) 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.
-     *  
-     * @param filterAttr
-     *            The class bean attributes which should be serialized
-     * 
-     * @return JSON string
-     * 
-     * @throws Exception
-     *             If JSON serialization or filter registration fails
-     */
-    public <T> String serializeOnlyFilter(Object src, Class<T> filterClass, 
Boolean cleanFilter,
-            String... filterAttr) throws Exception;
-
-    /**
-     * Serialize all object properties excluding provided filters attributes. 
If no filter is set, all attributes should be returned.
-     * 
-     * @param src
-     *            The Java object to serialize. By default the filtering is 
applied for this class. By default the class of the src object is the key for 
the filter object cached.
-     * @param filterClass
-     *            The class, which should be filtered out, if found as a 
property type.  
-     * @param cleanFilter
-     *            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
-     * 
-     * @return JSON string
-     * 
-     * @throws Exception
-     *             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 String serializeAllExceptFilter(Object src,
-            Boolean cleanFilter, String... filterAttr) throws Exception;
-    
-    /**
-     *  @see #serializeAllExceptFilter(Object, Class, Boolean, String...)
-     */
-    public String serializeAllExceptFilter(Object src,
-            String... filterAttr) throws Exception;
-
-    /**
-     * Adds an adapter (mixin, serializer,..) for the target class depending on
-     * the JsonService implementation.
-     * Cft. to {@link #addAdapter(String, Class, Object)}
-     * 
-     * @param name
-     *            The name of the adapter
-     * @param target
-     *            The target class for this adapter
-     * @param mixin
-     *            The adapter/mixin for the target class
-     * 
-     * @return the JsonService instance
-     * 
-     * @throws Exception
-     *             If adapter registration fails
-     */
-    public JsonService addAdapter(String name, Class target, Class mixin)
-            throws Exception;
-
-    /**
-     * Add an adapter (mixin, serializer,..) for the target class depending on
-     * the JsonService implementation. Adapters could by default not 
deregistered. If you want
-     * to get rid of them, you may try to reinit the service (or overwrite 
with the same target type, depending on
-     * implementation) 
-     * 
-     * @param name
-     *            The name of the adapter
-     * @param target
-     *            The target class for this adapter
-     * @param mixin
-     *            The adapter/mixin for the target object
-     *            (module/serializer/deserializer)
-     * 
-     * @return A JsonService instance
-     * 
-     * @throws Exception
-     *             if adapter registration fails
-     */
-    public JsonService addAdapter(String name, Class target, Object mixin)
-            throws Exception;
-
-    /**
-     * @param df
-     *            The {@link DateFormat} to be used by the JsonService, not 
null.
-     * 
-     * It could be provided by component configuration too.
-     * 
-     */
-    public void setDateFormat(final DateFormat df);
+       /** Avalon Identifier **/
+       String ROLE = JsonService.class.getName();
+
+       String SERVICE_NAME = ROLE;
+
+       /**
+        * Serializes a Java object
+        * 
+        * @param src the java object to be serialized, not null.
+        * 
+        * @return JSON string
+        * 
+        * @throws Exception if JSON serialization fails
+        */
+       String ser(Object src) throws Exception;
+
+       /**
+        * @param src        the java object to be serialized, not null.
+        * @param cleanCache a boolean value, not null. If <code>true</code>, 
try to
+        *                   refresh cache after serialization
+        * @return serialized object
+        * @throws Exception generic exception
+        */
+       String ser(Object src, Boolean cleanCache) throws Exception;
+
+       /**
+        * Serializes a Java object
+        * 
+        * @param src The Java object to be serialized
+        * @param type the Java Type, which should be used for the provided 
object
+        * @param <T> The class type
+        * @return JSON string
+        * @throws Exception If JSON serialization fails
+        */
+       <T> String ser(Object src, Class<T> type) throws Exception;
+       
+       /**
+        * Serialize an object
+        * 
+        * @param src The source object
+        * @param type The class type of the object
+        * @param <T> class type of the object
+        * @param cleanCache If <code>true</code>, try to clean cache after
+        *                   serialization
+        * 
+        *                   For other attributes @see {@link #ser(Object, 
Class)}
+        * 
+        * @return the serialized class
+        *                    
+        * @throws Exception if the JSON serialization fails
+        */
+       <T> String ser(Object src, Class<T> type, Boolean cleanCache) throws 
Exception;
+
+       /**
+        * Deserializing a JSON string
+        * 
+        * @param src  the JSON string to be deserialized
+        * @param type the Java Type to be used as a class
+        * @param <T> class type of the object
+        * @return the Java Object
+        * 
+        * @throws Exception if JSON deserialization fails
+        */
+       <T> T deSer(String src, Class<T> type) throws Exception;
+
+       /**
+        * This is to deserialize collections. Depending on the implementation 
either
+        * both collectiontype and elementType is needed or the elementType 
will be
+        * derived from the typed collectiontype.
+        * 
+        * @param json           The JSON string to be deserialized
+        * @param collectionType It could be just the collection or the typed
+        *                       collection. It may then be used to get the 
type for
+        *                       element type too. Cft. implementation tests 
for more
+        *                       details (GSON).
+        * @param elementType    The element type. This is need in any case to 
assure
+        *                       the generic checking.
+        * @param <T> class type of the object                       
+        * @return the generated Java Collection.
+        * @throws Exception if serialize collection fails
+        */
+       <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.
+        * 
+        * @param src the source object
+        * @param filterAttr filter attributes
+        * @return JSON string
+        * @throws Exception if fails
+        */
+       public 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.
+        * 
+        * @param filterAttr filter attributes
+        * @return JSON string
+        * @throws Exception if fails
+        */
+       public String serializeOnlyFilter(Object src, Boolean cleanFilter, 
String... filterAttr) throws Exception;
+
+       /**
+        * @see #serializeOnlyFilter(Object, Class, Boolean, String...) 
+        *      Caching is set to <code>false</code> for this method call.
+        *      
+        * @param src         The Java object to serialize
+        * @param filterClass The filter class
+        * @param <T> class type of the object
+        * @param filterAttr filter attributes
+        * @return JSON string
+        * @throws Exception if fails
+        */
+       public <T> String serializeOnlyFilter(Object src, Class<T> filterClass, 
String... filterAttr) throws Exception;
+
+       /**
+        * Serialize only object properties where filter attributes are 
provided. If no
+        * filter is set, no attributes should be returned.
+        * 
+        * @param src         The Java object to serialize
+        * @param filterClass By default filterClass is a) the class to be 
filtered
+        *                    (required for filtering list elements) b) the key 
in the
+        *                    filter object cached.
+        * @param <T> class type of the object
+        * @param cleanFilter 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
+        * 
+        * @return JSON string
+        * 
+        * @throws Exception If JSON serialization or filter registration fails
+        */
+       public <T> String serializeOnlyFilter(Object src, Class<T> filterClass, 
Boolean cleanFilter, String... filterAttr)
+                       throws Exception;
+
+       /**
+        * Serialize all object properties excluding provided filters 
attributes. If no
+        * filter is set, all attributes should be returned.
+        * 
+        * @param src         The Java object to serialize. By default the 
filtering is
+        *                    applied for this class. By default the class of 
the src
+        *                    object is the key for the filter object cached.
+        * @param filterClass The class, which should be filtered out, if found 
as a
+        *                    property type.
+        * @param <T> class type of the object
+        * @param cleanFilter 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
+        * 
+        * @return JSON string
+        * 
+        * @throws Exception 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>.
+        *      
+        * @param src         The Java object to serialize. By default the 
filtering is
+        *                    applied for this class. By default the class of 
the src
+        *                    object is the key for the filter object cached.
+        * @param <T> class type of the object
+        * @param filterClass The class, which should be filtered out, if found 
as a
+        *                    property type.
+        *                    
+        * @param filterAttr  The bean attributes which should not be serialized
+        * @return JSON string
+        * @throws Exception If JSON serialization or filter registration fails
+        */
+       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...)
+        * 
+        * @param src         The Java object to serialize. By default the 
filtering is
+        *                    applied for this class. By default the class of 
the src
+        *                    object is the key for the filter object cached.
+        *                    
+        * @param cleanFilter 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
+        * @return JSON string
+        * @throws Exception If JSON serialization or filter registration fails
+        */
+       public String serializeAllExceptFilter(Object src, Boolean cleanFilter, 
String... filterAttr) throws Exception;
+
+       /**
+        * @see #serializeAllExceptFilter(Object, Class, Boolean, String...)
+        * @param src         The Java object to serialize. By default the 
filtering is
+        *                    applied for this class. By default the class of 
the src
+        *                    object is the key for the filter object cached.
+        *                    
+        * @param filterAttr  The bean attributes which should not be serialized
+        * @return JSON string
+        * @throws Exception If JSON serialization or filter registration fails
+        */
+       public String serializeAllExceptFilter(Object src, String... 
filterAttr) throws Exception;
+
+       /**
+        * Adds an adapter (mixin, serializer,..) for the target class 
depending on the
+        * JsonService implementation. Cft. to
+        * {@link #addAdapter(String, Class, Object)}
+        * 
+        * @param name   The name of the adapter
+        * @param target The target class for this adapter
+        * @param mixin  The adapter/mixin for the target class
+        * 
+        * @return the JsonService instance
+        * 
+        * @throws Exception If adapter registration fails
+        */
+       public JsonService addAdapter(String name, Class target, Class mixin) 
throws Exception;
+
+       /**
+        * Add an adapter (mixin, serializer,..) for the target class depending 
on the
+        * JsonService implementation. Adapters could by default not 
deregistered. If
+        * you want to get rid of them, you may try to reinit the service (or 
overwrite
+        * with the same target type, depending on implementation)
+        * 
+        * @param name   The name of the adapter
+        * @param target The target class for this adapter
+        * @param mixin  The adapter/mixin for the target object
+        *               (module/serializer/deserializer)
+        * 
+        * @return A JsonService instance
+        * 
+        * @throws Exception if adapter registration fails
+        */
+       public JsonService addAdapter(String name, Class target, Object mixin) 
throws Exception;
+
+       /**
+        * @param df The {@link DateFormat} to be used by the JsonService, not 
null.
+        *           It could be provided by component configuration too.
+        * 
+        */
+       public void setDateFormat(final DateFormat df);
 
 }

Modified: turbine/fulcrum/trunk/json/api/src/site/site.xml
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/api/src/site/site.xml?rev=1845825&r1=1845824&r2=1845825&view=diff
==============================================================================
--- turbine/fulcrum/trunk/json/api/src/site/site.xml (original)
+++ turbine/fulcrum/trunk/json/api/src/site/site.xml Mon Nov  5 17:43:51 2018
@@ -22,7 +22,8 @@
   xsi:schemaLocation="http://maven.apache.org/DECORATION/1.4.0 
http://maven.apache.org/xsd/decoration-1.4.0.xsd";
   name="Fulcrum JSON API">
 
-<body>
+<body> 
+       <menu ref="reports"></menu>
 </body>
 
 </project>

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=1845825&r1=1845824&r2=1845825&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
 Mon Nov  5 17:43:51 2018
@@ -209,16 +209,19 @@ public class GSONBuilderService extends
     }
     
     /**
-     * Alternative method to calling {@link #gson#registerTypeAdapter(Object, 
Type)}.
+     * Alternative method to calling {@link #registerTypeAdapter(Object, Type)}
      * Note: Always use either this direct format call or the other adapter 
register call,
      * otherwise inconsistencies may occur!
      * 
-     * @param dformat
+     * @param dfStr date format string
      */
     public void setDateFormat(final String dfStr) {
         gson.setDateFormat(dfStr);
     }
 
+    /* (non-Javadoc)
+     * @see 
org.apache.fulcrum.json.JsonService#setDateFormat(java.text.DateFormat)
+     */
     @Override
     public void setDateFormat(final DateFormat df) {
         DateTypeAdapter dateTypeAdapter = new DateTypeAdapter();
@@ -233,6 +236,9 @@ public class GSONBuilderService extends
         // return gson.create().toJson( src );
     }
 
+    /* (non-Javadoc)
+     * @see 
org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+     */
     @Override
     public void configure(Configuration conf) throws ConfigurationException {
 
@@ -264,6 +270,9 @@ public class GSONBuilderService extends
         }
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.avalon.framework.activity.Initializable#initialize()
+     */
     @Override
     public void initialize() throws Exception {
         gson = new GsonBuilder();
@@ -376,6 +385,11 @@ public class GSONBuilderService extends
         }.init(clazz, filterAttrs);
     }
     
+    /**
+     * @param clazz the class to exclude
+     * @param filterAttrs bean elements not to be serialized
+     * @return
+     */
     private ExclusionStrategy include(Class clazz, String... filterAttrs) {
         return new ExclusionStrategy() {
 

Modified: 
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=1845825&r1=1845824&r2=1845825&view=diff
==============================================================================
--- 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/CustomModule.java
 (original)
+++ 
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/CustomModule.java
 Mon Nov  5 17:43:51 2018
@@ -27,6 +27,14 @@ public final class CustomModule<T> exten
 
     private static final long serialVersionUID = 1L;
 
+    /**
+     * Instantiate a custom module
+     * 
+     * @param name Name of module
+     * @param targetClazz The target class
+     * @param stdSer Standard serializer
+     * @param stdDeser  Standard de-serializer
+     */
     public CustomModule(String name, Class<T> targetClazz,
             StdSerializer<T> stdSer, StdDeserializer<T> stdDeser) {
         super(name, Version.unknownVersion());


Reply via email to