Author: gk
Date: Fri Apr 13 13:33:29 2018
New Revision: 1829072

URL: http://svn.apache.org/viewvc?rev=1829072&view=rev
Log:
Jackson 2
- variables renamed in test class
- JsonOrg JSONObject mapper extracted now in separate test class, adding tests

Added:
    
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JsonOrgJacksonMapperTest.java
   (with props)
Modified:
    
turbine/fulcrum/trunk/json/jackson2/src/java/org/apache/fulcrum/json/jackson/Jackson2MapperService.java
    
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JacksonMapperEnabledDefaultTypingTest.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/jackson2/src/test/org/apache/fulcrum/json/jackson/JsonPathJacksonTest.java

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=1829072&r1=1829071&r2=1829072&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
 Fri Apr 13 13:33:29 2018
@@ -168,6 +168,10 @@ public class Jackson2MapperService exten
         return (T) reader.readValue(json);
     }
     
+    public <T> T deSer(Object src, Class<T> type) throws Exception {
+         return mapper.convertValue( src, type);
+    }
+    
     public <T> Collection<T> deSerCollectionWithType(String json, Class<? 
extends Collection> collectionClass, Class<T> type)
             throws Exception {
         return mapper.readValue(json, mapper.getTypeFactory()

Modified: 
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JacksonMapperEnabledDefaultTypingTest.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JacksonMapperEnabledDefaultTypingTest.java?rev=1829072&r1=1829071&r2=1829072&view=diff
==============================================================================
--- 
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JacksonMapperEnabledDefaultTypingTest.java
 (original)
+++ 
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JacksonMapperEnabledDefaultTypingTest.java
 Fri Apr 13 13:33:29 2018
@@ -101,30 +101,30 @@ public class JacksonMapperEnabledDefault
     }
     @Test
     public void testSerializeWithCustomFilter() throws Exception {
-        Bean filteredBean = new Bean();
-        filteredBean.setName("joe");
-        String bean = sc.serializeOnlyFilter(filteredBean, Bean.class, "name");
+        Bean bean = new Bean();
+        bean.setName("joe");
+        String filteredBean  = sc.serializeOnlyFilter(bean, Bean.class, 
"name");
         assertEquals(
                 "Ser filtered Bean failed ",
                 
"{\"type\":\"org.apache.fulcrum.json.jackson.Bean\",\"name\":\"joe\"}",
-                bean);
+                filteredBean);
 
-        Rectangle filteredRectangle = new Rectangle(5, 10);
-        filteredRectangle.setName("jim");
-        String rectangle = sc.serializeOnlyFilter(filteredRectangle,
+        Rectangle rectangle = new Rectangle(5, 10);
+        rectangle.setName("jim");
+        String filteredRectangle = sc.serializeOnlyFilter(rectangle,
                 Rectangle.class, "w", "name");
         assertEquals("Ser filtered Rectangle failed ",
-                "{\"w\":5,\"name\":\"jim\"}", rectangle);
+                "{\"w\":5,\"name\":\"jim\"}", filteredRectangle );
     }
     @Test
     public void testSerializationCollectionWithFilter() throws Exception {
 
         List<Bean> beanList = new ArrayList<Bean>();
         for (int i = 0; i < 10; i++) {
-            Bean filteredBean = new Bean();
-            filteredBean.setName("joe" + i);
-            filteredBean.setAge(i);
-            beanList.add(filteredBean);
+            Bean bean = new Bean();
+            bean.setName("joe" + i);
+            bean.setAge(i);
+            beanList.add(bean);
         }
         String result = sc.serializeOnlyFilter(beanList, Bean.class, "name",
                 "age");
@@ -156,10 +156,10 @@ public class JacksonMapperEnabledDefault
 
         List<Bean> beanList = new ArrayList<Bean>();
         for (int i = 0; i < 10; i++) {
-            Bean filteredBean = new Bean();
-            filteredBean.setName("joe" + i);
-            filteredBean.setAge(i);
-            beanList.add(filteredBean);
+            Bean bean = new Bean();
+            bean.setName("joe" + i);
+            bean.setAge(i);
+            beanList.add(bean);
         }
         String result = sc.serializeOnlyFilter(beanList, Bean.class, "name",
                 "age");
@@ -179,10 +179,10 @@ public class JacksonMapperEnabledDefault
 
         List<Bean> beanList = new ArrayList<Bean>();
         for (int i = 0; i < 10; i++) {
-            Bean filteredBean = new Bean();
-            filteredBean.setName("joe" + i);
-            filteredBean.setAge(i);
-            beanList.add(filteredBean);
+            Bean bean = new Bean();
+            bean.setName("joe" + i);
+            bean.setAge(i);
+            beanList.add(bean);
         }
         String result = sc.serializeOnlyFilter(beanList, Bean.class, "name",
                 "age");
@@ -208,23 +208,23 @@ public class JacksonMapperEnabledDefault
     }
     @Test
     public void testSerializeWith2Mixins() throws Exception {
-        Bean filteredBean = new Bean();
-        filteredBean.setName("joe");
-        Rectangle filteredRectangle = new Rectangle(5, 10);
-        filteredRectangle.setName("jim");
+        Bean bean = new Bean();
+        bean.setName("joe");
+        Rectangle rectangle = new Rectangle(5, 10);
+        rectangle.setName("jim");
 
        String serRect =  sc.addAdapter("M4RMixin2", Rectangle.class,
-                Mixin2.class).ser(filteredRectangle);
+                Mixin2.class).ser(rectangle);
         assertEquals("Ser failed ", "{\"name\":\"jim\",\"width\":5}", serRect);
 
         //
-        String bean = sc.addAdapter("M4RBeanMixin", Bean.class,
-                BeanMixin.class).ser(filteredBean);;
+        String filteredBean = sc.addAdapter("M4RBeanMixin", Bean.class,
+                BeanMixin.class).ser(bean);;
         
         assertEquals(
                 "Ser filtered Bean failed ",
                 
"{\"type\":\"org.apache.fulcrum.json.jackson.Bean\",\"name\":\"joe\"}",
-                bean);
+                filteredBean);
     }
     @Test
     public void testSerializeWithMixinAndFilter() throws Exception {
@@ -242,55 +242,55 @@ public class JacksonMapperEnabledDefault
     }
     @Test
     public void testSerializeWithUnregisteredMixinAndFilter() throws Exception 
{
-        Bean filteredBean = new Bean();
-        filteredBean.setName("joe");
+        Bean bean = new Bean();
+        bean.setName("joe");
         //
         sc.addAdapter("M4RBeanMixin", Bean.class,
                 BeanMixin.class)
         .addAdapter("M4RBeanMixin", Bean.class,
                 null);
         // now profession is used after cleaning adapter
-        String bean = sc.serializeOnlyFilter(filteredBean, Bean.class, 
"profession");
+        String filteredBean = sc.serializeOnlyFilter(bean, Bean.class, 
"profession");
         assertEquals(
                 "Ser filtered Bean failed ",
                 
"{\"type\":\"org.apache.fulcrum.json.jackson.Bean\",\"profession\":\"\"}",
-                bean);
+                filteredBean);
     }
     @Test
     public void testMultipleSerializingWithMixinAndFilter() throws Exception {
-        Rectangle filteredRectangle = new Rectangle(5, 10);
-        filteredRectangle.setName("jim");
+        Rectangle rectangle = new Rectangle(5, 10);
+        rectangle.setName("jim");
         //
         sc.addAdapter("M4RMixin2", Rectangle.class,
                 Mixin2.class);
         
         // if serialization is done Jackson clean cache
-        String rectangle0 = sc.ser(filteredRectangle,Rectangle.class,true);
+        String rectangle0 = sc.ser(rectangle,Rectangle.class,true);
         assertEquals(
                 "Ser filtered Rectangle failed ",
                 "{\"name\":\"jim\",\"width\":5}",
                 rectangle0);
         // filtering out name, using width from mixin2 as a second filter
-        String rectangle = sc.serializeOnlyFilter(filteredRectangle, 
Rectangle.class, true, "width");
+        String rectangle1 = sc.serializeOnlyFilter(rectangle, Rectangle.class, 
true, "width");
         assertEquals(
                 "Ser filtered Rectangle failed ",
                 "{\"width\":5}",
-                rectangle);
+                rectangle1);
         // default for mixin
-       String rectangle1 = sc.ser(filteredRectangle);
+       String rectangle2 = sc.ser(rectangle);
        assertEquals(
               "Ser filtered Rectangle failed ",
               "{\"name\":\"jim\",\"width\":5}",
-              rectangle1);
+              rectangle2);
     }
     @Test
     public void testSerializationCollectionWithMixin() throws Exception {
         List<Bean> beanList = new ArrayList<Bean>();
         for (int i = 0; i < 10; i++) {
-            Bean filteredBean = new Bean();
-            filteredBean.setName("joe" + i);
-            filteredBean.setAge(i);
-            beanList.add(filteredBean);
+            Bean bean = new Bean();
+            bean.setName("joe" + i);
+            bean.setAge(i);
+            beanList.add(bean);
         }
         String result = sc.addAdapter("M4RMixin", Bean.class, BeanMixin.class)
                 .ser(beanList);
@@ -303,10 +303,10 @@ public class JacksonMapperEnabledDefault
     public void testDeSerializationCollectionWithMixin() throws Exception {
         List<Bean> beanList = new ArrayList<Bean>();
         for (int i = 0; i < 10; i++) {
-            Bean filteredBean = new Bean();
-            filteredBean.setName("joe" + i);
-            filteredBean.setAge(i);
-            beanList.add(filteredBean);
+            Bean bean = new Bean();
+            bean.setName("joe" + i);
+            bean.setAge(i);
+            beanList.add(bean);
         }
         String result = sc.addAdapter("M4RMixin", Bean.class, BeanMixin.class)
                 .ser(beanList);
@@ -325,10 +325,10 @@ public class JacksonMapperEnabledDefault
         components.add(new Rectangle(25, 3));
         components.add(new Rectangle(250, 30));
         for (int i = 0; i < 3; i++) {
-            Bean filteredBean = new Bean();
-            filteredBean.setName("joe" + i);
-            filteredBean.setAge(i);
-            components.add(filteredBean);
+            Bean bean = new Bean();
+            bean.setName("joe" + i);
+            bean.setAge(i);
+            components.add(bean);
         }
         sc.addAdapter("M4RMixin", Rectangle.class, Mixin.class).addAdapter(
                 "M4BeanRMixin", Bean.class, BeanMixin.class);

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=1829072&r1=1829071&r2=1829072&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
 Fri Apr 13 13:33:29 2018
@@ -186,13 +186,13 @@ public class JacksonMapperEnabledDefault
     }
     @Test
     public void testSerializeWithCustomFilter() throws Exception {
-        Bean filteredBean = new Bean();
-        filteredBean.setName("joe");
-        String bean = sc.serializeOnlyFilter(filteredBean, "name");
+        Bean bean = new Bean();
+        bean.setName("joe");
+        String filteredBean = sc.serializeOnlyFilter(bean, "name");
         assertEquals(
                 "Ser filtered Bean failed ",
                 "{\"name\":\"joe\"}",
-                bean);
+                filteredBean);
         Rectangle filteredRectangle = new Rectangle(5, 10);
         filteredRectangle.setName("jim");
         String rectangle = sc.serializeOnlyFilter(filteredRectangle,
@@ -205,28 +205,28 @@ public class JacksonMapperEnabledDefault
 
         List<Bean> beanList = new ArrayList<Bean>();
         for (int i = 0; i < 10; i++) {
-            Bean filteredBean = new Bean();
-            filteredBean.setName("joe" + i);
-            filteredBean.setAge(i);
-            beanList.add(filteredBean);
+            Bean bean = new Bean();
+            bean.setName("joe" + i);
+            bean.setAge(i);
+            beanList.add(bean);
         }
-        String result = sc.serializeOnlyFilter(beanList, Bean.class, "name",
+        String filteredResult = sc.serializeOnlyFilter(beanList, Bean.class, 
"name",
                 "age");
         assertEquals(
                 "Serialization of beans failed ",
                 
"[{'type':'org.apache.fulcrum.json.jackson.Bean','name':'joe0','age':0},{'type':'org.apache.fulcrum.json.jackson.Bean','name':'joe1','age':1},{'type':'org.apache.fulcrum.json.jackson.Bean','name':'joe2','age':2},{'type':'org.apache.fulcrum.json.jackson.Bean','name':'joe3','age':3},{'type':'org.apache.fulcrum.json.jackson.Bean','name':'joe4','age':4},{'type':'org.apache.fulcrum.json.jackson.Bean','name':'joe5','age':5},{'type':'org.apache.fulcrum.json.jackson.Bean','name':'joe6','age':6},{'type':'org.apache.fulcrum.json.jackson.Bean','name':'joe7','age':7},{'type':'org.apache.fulcrum.json.jackson.Bean','name':'joe8','age':8},{'type':'org.apache.fulcrum.json.jackson.Bean','name':'joe9','age':9}]",
-                result.replace('"', '\''));
+                filteredResult.replace('"', '\''));
     }
     @Test
     public void testDeserializationCollectionWithFilter() throws Exception {
         List<Bean> beanList = new ArrayList<Bean>();
         for (int i = 0; i < 10; i++) {
-            Bean filteredBean = new Bean();
-            filteredBean.setName("joe" + i);
-            filteredBean.setAge(i);
-            beanList.add(filteredBean);
+            Bean bean = new Bean();
+            bean.setName("joe" + i);
+            bean.setAge(i);
+            beanList.add(bean);
         }
-        String result = sc.serializeOnlyFilter(beanList, Bean.class, "name",
+        String filteredResult = sc.serializeOnlyFilter(beanList, Bean.class, 
"name",
                 "age");
         //System.out.println("res:"+result);
         // could not use TypeReference as JSON string has no type set for 
array:
@@ -235,7 +235,7 @@ public class JacksonMapperEnabledDefault
         // 
         // -> need to use constructCollectionType        
         Class clazz = Class.forName("org.apache.fulcrum.json.jackson.Bean");
-        List<Bean> beanList2 = (List<Bean>)sc.deSerCollection(result, new 
ArrayList(),clazz);
+        List<Bean> beanList2 = (List<Bean>)sc.deSerCollection(filteredResult, 
new ArrayList(),clazz);
         assertTrue("DeSer failed ", beanList2.size() == 10);
         for (Bean bean : beanList2) {
             assertEquals("DeSer failed ", Bean.class, bean.getClass());
@@ -246,10 +246,10 @@ public class JacksonMapperEnabledDefault
             throws Exception {
         List<Bean> beanList = new ArrayList<Bean>();
         for (int i = 0; i < 10; i++) {
-            Bean filteredBean = new Bean();
-            filteredBean.setName("joe" + i);
-            filteredBean.setAge(i);
-            beanList.add(filteredBean);
+            Bean bean = new Bean();
+            bean.setName("joe" + i);
+            bean.setAge(i);
+            beanList.add(bean);
         }
         String result = sc.serializeOnlyFilter(beanList, Bean.class, "name",
                 "age");
@@ -280,8 +280,8 @@ public class JacksonMapperEnabledDefault
     }
     @Test
     public void testSerializeWith2Mixins() throws Exception {
-        Bean filteredBean = new Bean();
-        filteredBean.setName("joe");
+        Bean bean = new Bean();
+        bean.setName("joe");
         Rectangle filteredRectangle = new Rectangle(5, 10);
         filteredRectangle.setName("jim");
 
@@ -289,13 +289,13 @@ public class JacksonMapperEnabledDefault
                 Mixin2.class).ser(filteredRectangle);
         assertEquals("Ser failed ", "{\"name\":\"jim\",\"width\":5}", serRect);
         //
-        String bean = sc.addAdapter("M4RBeanMixin", Bean.class,
-                BeanMixin.class).ser(filteredBean);;
+        String filteredBean = sc.addAdapter("M4RBeanMixin", Bean.class,
+                BeanMixin.class).ser(bean);;
         
         assertEquals(
                 "Ser filtered Bean failed ",
                 "{\"name\":\"joe\"}",
-                bean);
+                filteredBean);
     }
     @Test
     public void testSerializeWithMixinAndFilter() throws Exception {
@@ -312,52 +312,52 @@ public class JacksonMapperEnabledDefault
     }
     @Test
     public void testSerializeWithUnregisteredMixinAndFilter() throws Exception 
{
-        Bean filteredBean = new Bean();
-        filteredBean.setName("joe");
+        Bean bean = new Bean();
+        bean.setName("joe");
         sc.addAdapter("M4RBeanMixin", Bean.class,
                 BeanMixin.class)
         .addAdapter("M4RBeanMixin", Bean.class,
                 null);
         // now profession is used after cleaning adapter
-        String bean = sc.serializeOnlyFilter(filteredBean, Bean.class, 
"profession");
+        String filteredBeanSer = sc.serializeOnlyFilter(bean, Bean.class, 
"profession");
         assertEquals(
                 "Ser filtered Bean failed ",
                 "{\"profession\":\"\"}",
-                bean);
+                filteredBeanSer);
     }
     @Test
     public void testMultipleSerializingWithMixinAndFilter() throws Exception {
-        Rectangle filteredRectangle = new Rectangle(5, 10);
-        filteredRectangle.setName("jim");
+        Rectangle rectangle = new Rectangle(5, 10);
+        rectangle.setName("jim");
         sc.addAdapter("M4RMixin2", Rectangle.class,
                 Mixin2.class);
         // if serialization is done Jackson clean cache
-        String rectangle0 = sc.ser(filteredRectangle,Rectangle.class,true);
+        String rectangle0 = sc.ser(rectangle,Rectangle.class,true);
         assertEquals(
                 "Ser filtered Rectangle failed ",
                 "{\"name\":\"jim\",\"width\":5}",
                 rectangle0);
         // filtering out name, using width from mixin2 as a second filter
-        String rectangle = sc.serializeOnlyFilter(filteredRectangle, 
Rectangle.class, true, "width");
+        String rectangle1 = sc.serializeOnlyFilter(rectangle, Rectangle.class, 
true, "width");
         assertEquals(
                 "Ser filtered Rectangle failed ",
                 "{\"width\":5}",
-                rectangle);
+                rectangle1);
         // default for mixin
-       String rectangle1 = sc.ser(filteredRectangle);
+       String rectangle2 = sc.ser(rectangle);
        assertEquals(
               "Ser filtered Rectangle failed ",
               "{\"name\":\"jim\",\"width\":5}",
-              rectangle1);
+              rectangle2);
     }
     @Test
     public void testSerializationCollectionWithMixin() throws Exception {
         List<Bean> beanList = new ArrayList<Bean>();
         for (int i = 0; i < 10; i++) {
-            Bean filteredBean = new Bean();
-            filteredBean.setName("joe" + i);
-            filteredBean.setAge(i);
-            beanList.add(filteredBean);
+            Bean bean = new Bean();
+            bean.setName("joe" + i);
+            bean.setAge(i);
+            beanList.add(bean);
         }
         String result = sc.addAdapter("M4RMixin", Bean.class, BeanMixin.class)
                 .ser(beanList);
@@ -370,10 +370,10 @@ public class JacksonMapperEnabledDefault
     public void testDeSerializationCollectionWithMixin() throws Exception {
         List<Bean> beanList = new ArrayList<Bean>();
         for (int i = 0; i < 10; i++) {
-            Bean filteredBean = new Bean();
-            filteredBean.setName("joe" + i);
-            filteredBean.setAge(i);
-            beanList.add(filteredBean);
+            Bean bean = new Bean();
+            bean.setName("joe" + i);
+            bean.setAge(i);
+            beanList.add(bean);
         }
         String result = sc.addAdapter("M4RMixin", Bean.class, BeanMixin.class)
                 .ser(beanList);
@@ -394,10 +394,10 @@ public class JacksonMapperEnabledDefault
         components.add(new Rectangle(25, 3));
         components.add(new Rectangle(250, 30));
         for (int i = 0; i < 3; i++) {
-            Bean filteredBean = new Bean();
-            filteredBean.setName("joe" + i);
-            filteredBean.setAge(i);
-            components.add(filteredBean);
+            Bean bean = new Bean();
+            bean.setName("joe" + i);
+            bean.setAge(i);
+            components.add(bean);
         }
         // property w->width, BeanMixin:  name ignore other properties
         sc.addAdapter("M4RMixin", Rectangle.class, Mixin.class).addAdapter(

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=1829072&r1=1829071&r2=1829072&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
 Fri Apr 13 13:33:29 2018
@@ -37,15 +37,12 @@ import org.apache.fulcrum.json.JsonServi
 import org.apache.fulcrum.json.Rectangle;
 import org.apache.fulcrum.json.TestClass;
 import org.apache.fulcrum.testcontainer.BaseUnit4Test;
-import org.json.JSONArray;
-import org.json.JSONObject;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule;
 
 /**
  * Jackson2 JSON Test
@@ -97,17 +94,18 @@ public class JacksonMapperTest extends B
     }
     @Test
     public void testSerializeWithCustomFilter() throws Exception {
-        Bean filteredBean = new Bean();
-        filteredBean.setName("joe");
-        String bean = sc.serializeOnlyFilter(filteredBean, Bean.class, "name");
-        assertEquals("Ser filtered Bean failed ", "{\"name\":\"joe\"}", bean);
-
-        Rectangle filteredRectangle = new Rectangle(5, 10);
-        filteredRectangle.setName("jim");
-        String rectangle = sc.serializeOnlyFilter(filteredRectangle,
+        Bean bean = new Bean();
+        bean.setName("joe");
+        bean.setAge(12);
+        String filteredBean  = sc.serializeOnlyFilter(bean, Bean.class, 
"name");
+        assertEquals("Ser filtered Bean failed ", "{\"name\":\"joe\"}", 
filteredBean);
+
+        Rectangle rectangle = new Rectangle(5, 10);
+        rectangle.setName("jim");
+        String filteredRectangle  = sc.serializeOnlyFilter(rectangle,
                 Rectangle.class, "w", "name");
         assertEquals("Ser filtered Rectangle failed ",
-                "{\"w\":5,\"name\":\"jim\"}", rectangle);
+                "{\"w\":5,\"name\":\"jim\"}", filteredRectangle);
 
     }
     @Test
@@ -115,17 +113,17 @@ public class JacksonMapperTest extends B
 
         List<Bean> beanList = new ArrayList<Bean>();
         for (int i = 0; i < 10; i++) {
-            Bean filteredBean = new Bean();
-            filteredBean.setName("joe" + i);
-            filteredBean.setAge(i);
-            beanList.add(filteredBean);
+            Bean bean = new Bean();
+            bean.setName("joe" + i);
+            bean.setAge(i);
+            beanList.add(bean);
         }
-        String result = sc.serializeOnlyFilter(beanList, Bean.class, "name",
+        String filteredResult = sc.serializeOnlyFilter(beanList, Bean.class, 
"name",
                 "age");
         assertEquals(
                 "Serialization of beans failed ",
                 
"[{'name':'joe0','age':0},{'name':'joe1','age':1},{'name':'joe2','age':2},{'name':'joe3','age':3},{'name':'joe4','age':4},{'name':'joe5','age':5},{'name':'joe6','age':6},{'name':'joe7','age':7},{'name':'joe8','age':8},{'name':'joe9','age':9}]",
-                result.replace('"', '\''));
+                filteredResult.replace('"', '\''));
     }
 
     @Test
@@ -133,15 +131,15 @@ public class JacksonMapperTest extends B
 
         List<Bean> beanList = new ArrayList<Bean>();
         for (int i = 0; i < 10; i++) {
-            Bean filteredBean = new Bean();
-            filteredBean.setName("joe" + i);
-            filteredBean.setAge(i);
-            beanList.add(filteredBean);
+            Bean bean = new Bean();
+            bean.setName("joe" + i);
+            bean.setAge(i);
+            beanList.add(bean);
         }
-        String result = sc.serializeOnlyFilter(beanList, Bean.class, "name",
+        String filteredResult = sc.serializeOnlyFilter(beanList, Bean.class, 
"name",
                 "age");
         List<Bean> beanList2 = (List<Bean>) ((Jackson2MapperService) sc)
-                .deSerCollectionWithType(result, List.class, Bean.class);
+                .deSerCollectionWithType(filteredResult, List.class, 
Bean.class);
         assertTrue("DeSer failed ", beanList2.size() == 10);
         for (Bean bean : beanList2) {
             assertEquals("DeSer failed ", Bean.class, bean.getClass());
@@ -153,14 +151,14 @@ public class JacksonMapperTest extends B
 
         List<Bean> beanList = new ArrayList<Bean>();
         for (int i = 0; i < 10; i++) {
-            Bean filteredBean = new Bean();
-            filteredBean.setName("joe" + i);
-            filteredBean.setAge(i);
-            beanList.add(filteredBean);
+            Bean bean = new Bean();
+            bean.setName("joe" + i);
+            bean.setAge(i);
+            beanList.add(bean);
         }
-        String result = sc.serializeOnlyFilter(beanList, Bean.class, "name",
+        String filteredResult = sc.serializeOnlyFilter(beanList, Bean.class, 
"name",
                 "age");
-        Object beanList2 = sc.deSer(result, List.class);
+        Object beanList2 = sc.deSer(filteredResult, List.class);
         assertTrue("DeSer failed ", beanList2 instanceof List);
         assertTrue("DeSer failed ", ((List) beanList2).size() == 10);
         for (int i = 0; i < ((List) beanList2).size(); i++) {
@@ -173,68 +171,18 @@ public class JacksonMapperTest extends B
         }
     }
     
-    // support for org.json mapping 
-    @Test
-    public void testDeSerToORGJSONCollectionObject() throws Exception {
-        // test array
-         List<Bean> beanResults = new ArrayList<Bean> ( );
-         Bean tu = new Bean();
-         tu.setName("jim jar");
-         beanResults.add(tu);
-         Bean tu2 = new Bean();
-         tu2.setName("jim2 jar2");
-         tu2.setAge(45);
-         beanResults.add(tu2);
-         
-         String[] filterAttr = {"name", "age" };   
-         String filteredSerList = sc.serializeOnlyFilter(beanResults, 
Bean.class, filterAttr);
-         logger.debug("serList: "+ filteredSerList);
-   
-         sc.addAdapter(null, null,new JsonOrgModule());
-         //((Jackson2MapperService)sc).registerModule(new JsonOrgModule());
-         
-         JSONArray jsonOrgResult = sc.deSer(filteredSerList, 
JSONArray.class);//readValue(serList, JSONArray.class);
-         logger.debug("jsonOrgResult: "+ jsonOrgResult.toString(2));
-         assertEquals("DeSer failed ", "jim jar", 
((JSONObject)(jsonOrgResult.get(0))).get("name") );
-         assertEquals("DeSer failed ", 45, 
((JSONObject)(jsonOrgResult.get(1))).get("age") );      
-    }
-    
-    // support for org.json mapping 
-    @Test
-    public void testSerToORGJSONCollectionObject() throws Exception {
-  
-        // test array
-         List<Bean> userResults = new ArrayList<Bean> ( );
-         Bean tu = new Bean();
-         tu.setName("jim jar");
-         userResults.add(tu);
-         Bean tu2 = new Bean();
-         tu2.setName("jim2 jar2");
-         tu2.setAge(45);
-         userResults.add(tu2);
-         
-         String[] filterAttr = {"name", "age" };
-         
-         sc.addAdapter(null, null,new JsonOrgModule());
-         //((Jackson2MapperService)sc).registerModule(new JsonOrgModule());
-         String filteredSerList = sc.serializeOnlyFilter(userResults, 
Bean.class, filterAttr);
-         logger.debug("serList: "+ filteredSerList);
-         
-    }
-    
     @Test
     public void testSerializeWithMixin() throws Exception {
-        Rectangle filteredRectangle = new Rectangle(5, 10);
-        filteredRectangle.setName("jim");
-        String serRect = sc
-                .addAdapter("M4RMixin", Rectangle.class, Mixin.class).ser(
-                        filteredRectangle);
-        assertEquals("Ser failed ", "{\"width\":5}", serRect);
+        Rectangle rectangle = new Rectangle(5, 10);
+        rectangle.setName("jim");
+        String filteredRectangle = sc
+                .addAdapter("M4RMixin", Rectangle.class, 
Mixin.class).ser(rectangle);
+        assertEquals("Ser failed ", "{\"width\":5}", filteredRectangle);
     }
     @Test
     public void testSerializeWith2Mixins() throws Exception {
-        Bean filteredBean = new Bean();
-        filteredBean.setName("joe");
+        Bean bean = new Bean();
+        bean.setName("joe");
         Rectangle filteredRectangle = new Rectangle(5, 10);
         filteredRectangle.setName("jim");
 
@@ -242,26 +190,37 @@ public class JacksonMapperTest extends B
                 Mixin2.class).ser(filteredRectangle);
         assertEquals("Ser failed ", "{\"name\":\"jim\",\"width\":5}", serRect);
 
-        String bean = sc.serializeOnlyFilter(filteredBean, Bean.class, "name");
-        assertEquals("Ser filtered Bean failed ", "{\"name\":\"joe\"}", bean);
+        String filteredBean = sc.serializeOnlyFilter(bean, Bean.class, "name");
+        assertEquals("Ser filtered Bean failed ", "{\"name\":\"joe\"}", 
filteredBean);
     }
     @Test
     public void testSerializationCollectionWithMixin() throws Exception {
 
         List<Bean> beanList = new ArrayList<Bean>();
         for (int i = 0; i < 10; i++) {
-            Bean filteredBean = new Bean();
-            filteredBean.setName("joe" + i);
-            filteredBean.setAge(i);
-            beanList.add(filteredBean);
+            Bean bean = new Bean();
+            bean.setName("joe" + i);
+            bean.setAge(i);
+            beanList.add(bean);
         }
-        String result = sc.addAdapter("M4RMixin", Bean.class, BeanMixin.class)
+        String filterResult = sc.addAdapter("M4RMixin", Bean.class, 
BeanMixin.class)
                 .ser(beanList);
         assertEquals(
                 "Serialization of beans failed ",
                 
"[{'name':'joe0'},{'name':'joe1'},{'name':'joe2'},{'name':'joe3'},{'name':'joe4'},{'name':'joe5'},{'name':'joe6'},{'name':'joe7'},{'name':'joe8'},{'name':'joe9'}]",
-                result.replace('"', '\''));
+                filterResult.replace('"', '\''));
     }
+    
+    @Test
+    public void testSerializationBeanWithMixin() throws Exception {
+        Bean bean = new Bean();
+        bean.setName("joe1");
+        bean.setAge(1);
+        String filterResult = sc.addAdapter("M4RMixin", Bean.class, 
BeanMixin.class)
+                .ser(bean);
+        logger.debug("filterResult: "+ filterResult.toString());
+    }
+    
     @Test
     public void testDeSerUnQuotedObject() throws Exception {
         String jsonString = "{name:\"joe\"}";
@@ -288,14 +247,14 @@ public class JacksonMapperTest extends B
 
         List<Bean> beanList = new ArrayList<Bean>();
         for (int i = 0; i < 10; i++) {
-            Bean filteredBean = new Bean();
-            filteredBean.setName("joe" + i);
-            filteredBean.setAge(i);
-            beanList.add(filteredBean);
+            Bean bean = new Bean();
+            bean.setName("joe" + i);
+            bean.setAge(i);
+            beanList.add(bean);
         }
-        String result = sc.addAdapter("M4RMixin", Bean.class, BeanMixin.class)
+        String filterResult = sc.addAdapter("M4RMixin", Bean.class, 
BeanMixin.class)
                 .ser(beanList);
-        Object beanList2 = sc.deSer(result,
+        Object beanList2 = sc.deSer(filterResult,
                 List.class);
         assertTrue("DeSer failed ", beanList2 instanceof List);
         assertTrue("DeSer failed ", ((List) beanList2).size() == 10);
@@ -377,7 +336,7 @@ public class JacksonMapperTest extends B
     }
 
     public static abstract class BeanMixin {
-        void BeanMixin() {
+        BeanMixin() {
         }
 
         @JsonIgnore

Added: 
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JsonOrgJacksonMapperTest.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JsonOrgJacksonMapperTest.java?rev=1829072&view=auto
==============================================================================
--- 
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JsonOrgJacksonMapperTest.java
 (added)
+++ 
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JsonOrgJacksonMapperTest.java
 Fri Apr 13 13:33:29 2018
@@ -0,0 +1,149 @@
+package org.apache.fulcrum.json.jackson;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.fulcrum.json.JsonService;
+import org.apache.fulcrum.testcontainer.BaseUnit4Test;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule;
+
+/**
+ * Jackson2 JSON Test
+ * 
+ * Test without type setting 
+ * 
+ * @author gk
+ * @version $Id: JacksonMapperTest.java 1800753 2017-07-04 11:00:03Z gk $
+ */
+public class JsonOrgJacksonMapperTest extends BaseUnit4Test {
+    
+    private JsonService sc = null;
+    Logger logger;
+
+    @Before
+    public void setUp() throws Exception {
+        sc = (JsonService) this.lookup(JsonService.ROLE);
+        sc.addAdapter(null, null,new JsonOrgModule());
+        //((Jackson2MapperService)sc).registerModule(new JsonOrgModule());
+        logger = new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG);
+    }
+    
+    // support for org.json mapping 
+    @Test
+    public void testDeSerToORGJSONCollectionObject() throws Exception {
+        // test array
+         List<Bean> beanResults = new ArrayList<Bean> ( );
+         Bean tu = new Bean();
+         tu.setName("jim jar");
+         beanResults.add(tu);
+         Bean tu2 = new Bean();
+         tu2.setName("jim2 jar2");
+         tu2.setAge(45);
+         beanResults.add(tu2);
+         String[] filterAttr = {"name", "age" };   
+         String filteredSerList = sc.serializeOnlyFilter(beanResults, 
Bean.class, filterAttr);
+         logger.debug("serList: "+ filteredSerList);
+         JSONArray jsonOrgResult = sc.deSer(filteredSerList, 
JSONArray.class);//readValue(serList, JSONArray.class);
+         logger.debug("jsonOrgResult: "+ jsonOrgResult.toString(2));
+         assertEquals("DeSer failed ", "jim jar", 
((JSONObject)(jsonOrgResult.get(0))).get("name") );
+         assertEquals("DeSer failed ", 45, 
((JSONObject)(jsonOrgResult.get(1))).get("age") );      
+    }
+    
+    // support for org.json mapping 
+    @Test
+    public void testSerToORGJSONCollectionObject() throws Exception {
+        // test array
+         List<Bean> beanList = new ArrayList<Bean> ( );
+         Bean tu = new Bean();
+         tu.setName("jim jar");
+         beanList.add(tu);
+         Bean tu2 = new Bean();
+         tu2.setName("jim2 jar2");
+         tu2.setAge(45);
+         beanList.add(tu2);
+         String[] filterAttr = {"name", "age" };
+         JSONArray jsonArray 
=((Jackson2MapperService)sc).getMapper().convertValue( beanList, JSONArray 
.class );
+         logger.debug("jsonArray: "+ jsonArray.toString(2));
+         assertEquals("Get JSONObject from jsonArray failed ", "jim jar", 
((JSONObject)jsonArray.get( 0 )).get( "name" ));
+    }
+    
+    // support for org.json mapping 
+    @Test
+    public void testSerToORGJSONObject() throws Exception {
+        Bean bean = new Bean();
+        bean.setName("joe");
+        bean.setAge(12);
+        JSONObject jsonObject 
=((Jackson2MapperService)sc).getMapper().convertValue( bean, JSONObject.class );
+        logger.debug("jsonObject: "+ jsonObject.toString(2));
+        assertEquals("Get name from jsonObject failed ", "joe", 
jsonObject.get( "name" ));
+    }
+    
+    @Test
+    public void testFilteredBeanAfterDeSerToORGJSONObject() throws Exception {
+        Bean bean = new Bean();
+        bean.setName("joe2");
+        bean.setAge(12);
+        //same as ((Jackson2MapperService)sc).getMapper().convertValue( bean, 
JSONObject.class );
+        JSONObject jsonObject =((Jackson2MapperService)sc).deSer( bean, 
JSONObject.class );
+        logger.debug("jsonObject: "+ jsonObject.toString(2));
+        //  without no filter is applied, filter on original bean requires new 
mapper, bug ?
+        ((Jackson2MapperService)sc).initialize();// need to get fresh mapper
+        String[] filterAttr = {"name" };
+        String filteredBean = sc.serializeOnlyFilter(bean, Bean.class, 
filterAttr);
+        assertEquals("Ser filtered Bean failed ", "{\"name\":\"joe2\"}", 
filteredBean);
+        logger.debug("filteredBean: "+ filteredBean.toString());
+    }
+    
+    @Test
+    public void testFilteredJSONObjectAfterDeSerToORGJSONObject() throws 
Exception {
+        Bean bean = new Bean();
+        bean.setName("joe3");
+        bean.setAge(22);
+        // alternatively two step instead of calling convertValue, which does 
not affect filtering
+        String serBean = sc.ser( bean, Bean.class );
+        JSONObject jsonObject = sc.deSer( serBean, JSONObject.class );
+        logger.debug("jsonObject: "+ jsonObject.toString(2));
+        // retrieve hashmap to allow filtering by SimpleBeanPropertyFilter 
+        String serJsonObject = sc.ser( jsonObject, JSONObject.class );
+        Map mapOfJsonObject = sc.deSer( serJsonObject, HashMap.class );
+        String[] filterAttr = {"name" };
+        String filteredJsonObject = sc.serializeOnlyFilter(mapOfJsonObject, 
filterAttr);
+        assertEquals("Ser filtered JSONObject failed ", "{\"name\":\"joe3\"}", 
filteredJsonObject);
+        logger.debug("filteredJsonObject: "+ filteredJsonObject.toString());
+        // works without init
+        String filteredBean = sc.serializeOnlyFilter(bean, Bean.class, 
filterAttr);
+        assertEquals("Ser filtered Bean failed ", "{\"name\":\"joe3\"}", 
filteredBean);
+        logger.debug("filteredBean: "+ filteredBean.toString());
+    }
+
+}

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

Modified: 
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JsonPathJacksonTest.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JsonPathJacksonTest.java?rev=1829072&r1=1829071&r2=1829072&view=diff
==============================================================================
--- 
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JsonPathJacksonTest.java
 (original)
+++ 
turbine/fulcrum/trunk/json/jackson2/src/test/org/apache/fulcrum/json/jackson/JsonPathJacksonTest.java
 Fri Apr 13 13:33:29 2018
@@ -79,7 +79,6 @@ public class JsonPathJacksonTest extends
                 fail(e.getMessage());
             }
         }
-
     }
 
     @Test


Reply via email to