Author: gk
Date: Mon Jun 8 14:08:52 2015
New Revision: 1684192
URL: http://svn.apache.org/r1684192
Log:
- Define more precise border case behaviour
- Remove null argument tests
Modified:
turbine/fulcrum/trunk/json/api/src/java/org/apache/fulcrum/json/JsonService.java
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/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=1684192&r1=1684191&r2=1684192&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 Jun 8 14:08:52 2015
@@ -152,7 +152,7 @@ public interface JsonService {
String... filterAttr) throws Exception;
/**
- * Serialize only object properties where filter attributes are provided
+ * 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
@@ -174,7 +174,7 @@ public interface JsonService {
String... filterAttr) throws Exception;
/**
- * Serialize all object properties excluding provided filters attributes
+ * 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
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=1684192&r1=1684191&r2=1684192&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
Mon Jun 8 14:08:52 2015
@@ -273,8 +273,8 @@ public class Jackson2MapperService exten
PropertyFilter pf = null;
if (filterAttr != null)
pf = SimpleBeanPropertyFilter.serializeAllExcept(filterAttr);
- else
- pf = SimpleBeanPropertyFilter.serializeAllExcept("dummy");
+ else if (filterClasses == null) //no filter
+ return ser(src, clean);
return filter(src, filterClasses, pf, clean, true);
}
@@ -301,13 +301,15 @@ public class Jackson2MapperService exten
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) {
+ if (filterAttr != null && filterAttr.length > 0 && filterAttr[0] !=
"") {
pf = SimpleBeanPropertyFilter.filterOutAllExcept(filterAttr);
getLogger().debug("setting filteroutAllexcept filter for size of
filterAttr: " + filterAttr.length);
} else {
+ getLogger().warn("no filter attributes set!");
pf = SimpleBeanPropertyFilter.filterOutAllExcept("dummy");
}
return filter(src, filterClasses, pf, refresh, false);
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=1684192&r1=1684191&r2=1684192&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
Mon Jun 8 14:08:52 2015
@@ -68,7 +68,7 @@ public class DefaultServiceTest extends
//@Test
// the default test class: one String field, one Map
public void testSerializeExcludeNothing() throws Exception {
- String serJson = sc.serializeAllExceptFilter(new TestClass("mytest"),
(String[]) null);
+ String serJson = sc.serializeAllExceptFilter(new TestClass("mytest"));
assertEquals(
"Serialization failed ",
"{\"container\":{\"cf\":\"Config.xml\"},\"configurationName\":\"Config.xml\",\"name\":\"mytest\"}",
@@ -78,11 +78,11 @@ public class DefaultServiceTest extends
// jackson does not deep exclusion of class types (by default?)
public void testSerializeExcludeClass() throws Exception {
String serJson = sc.serializeAllExceptFilter(new TestClass("mytest"),
- String.class, (String[]) null);
+ String.class);
assertEquals("Serialization failed ",
"{\"container\":{\"cf\":\"Config.xml\"}}", serJson);
}
-
+
public void testSerializeExcludeClassAndField() throws Exception {
String serJson =
((Jackson2MapperService)sc).serializeAllExceptFilter(new TestClass("mytest"),
new Class[] { TestClass.class, String.class} , "container");