Skip to content

Commit f144070

Browse files
committed
Add a convenience "no-op" filter implementation
1 parent 4a06170 commit f144070

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/main/java/com/fasterxml/jackson/databind/ser/impl/SimpleBeanPropertyFilter.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* because it can provide default implementation for any methods that may
1818
* be added in {@link PropertyFilter} (as unfortunate as additions may be).
1919
*/
20-
public abstract class SimpleBeanPropertyFilter
20+
public class SimpleBeanPropertyFilter
2121
implements BeanPropertyFilter, PropertyFilter
2222
// sub-classes must also implement java.io.Serializable
2323
{
@@ -29,6 +29,17 @@ public abstract class SimpleBeanPropertyFilter
2929

3030
protected SimpleBeanPropertyFilter() { }
3131

32+
/**
33+
* Convenience factory method that will return a "no-op" filter that will
34+
* simply just serialize all properties that are given, and filter out
35+
* nothing.
36+
*
37+
* @since 2.5
38+
*/
39+
public static SimpleBeanPropertyFilter serializeAll(Set<String> properties) {
40+
return new FilterExceptFilter(properties);
41+
}
42+
3243
/**
3344
* Factory method to construct filter that filters out all properties <b>except</b>
3445
* ones includes in set
@@ -105,15 +116,23 @@ public void serializeAsElement(Object elementValue,
105116
* Method called to determine whether property will be included
106117
* (if 'true' returned) or filtered out (if 'false' returned)
107118
*/
108-
protected abstract boolean include(BeanPropertyWriter writer);
119+
protected boolean include(BeanPropertyWriter writer) {
120+
return true;
121+
}
109122

110123
/**
124+
* Method called to determine whether property will be included
125+
* (if 'true' returned) or filtered out (if 'false' returned)
126+
*
111127
* @since 2.3
112128
*/
113-
protected abstract boolean include(PropertyWriter writer);
129+
protected boolean include(PropertyWriter writer) {
130+
return true;
131+
}
114132

115133
/**
116-
* Method that defines what to do with container elements;
134+
* Method that defines what to do with container elements
135+
* (values contained in an array or {@link java.util.Collection}:
117136
* default implementation simply writes them out.
118137
*
119138
* @since 2.3

src/test/java/com/fasterxml/jackson/databind/struct/PojoAsArray646Test.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ public class PojoAsArray646Test extends BaseMapTest
1111
@JsonFormat(shape = JsonFormat.Shape.ARRAY)
1212
@JsonPropertyOrder(alphabetic = true)
1313
static class Outer {
14-
15-
private Map<String, TheItem> attributes;
14+
protected Map<String, TheItem> attributes;
1615

1716
public Outer() {
1817
attributes = new HashMap<String, TheItem>();

0 commit comments

Comments
 (0)