Add `JsonSerializer.withFilterId(...)` mutant factory method
diff --git a/release-notes/VERSION b/release-notes/VERSION
index b5d8807..83a046d 100644
--- a/release-notes/VERSION
+++ b/release-notes/VERSION
@@ -80,6 +80,7 @@
#848: Custom serializer not used if POJO has `@JsonValue`
#849: Possible problem with `NON_EMPTY` exclusion, `int`s, `Strings`
- Remove old cglib compatibility tests; cause problems in Eclipse
+- Add `withFilterId()` method in `JsonSerializer` (demote from `BeanSerializer`)
2.5.5 (not released)
diff --git a/src/main/java/com/fasterxml/jackson/databind/JsonDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/JsonDeserializer.java
index a370b47..9e3ab90 100644
--- a/src/main/java/com/fasterxml/jackson/databind/JsonDeserializer.java
+++ b/src/main/java/com/fasterxml/jackson/databind/JsonDeserializer.java
@@ -121,8 +121,7 @@
* that do not explicitly add support do not necessarily support
* update-existing-value operation (esp. immutable types)
*/
- public T deserialize(JsonParser p, DeserializationContext ctxt,
- T intoValue)
+ public T deserialize(JsonParser p, DeserializationContext ctxt, T intoValue)
throws IOException, JsonProcessingException
{
throw new UnsupportedOperationException("Can not update object of type "
diff --git a/src/main/java/com/fasterxml/jackson/databind/JsonSerializer.java b/src/main/java/com/fasterxml/jackson/databind/JsonSerializer.java
index ddfd5ec..4d30158 100644
--- a/src/main/java/com/fasterxml/jackson/databind/JsonSerializer.java
+++ b/src/main/java/com/fasterxml/jackson/databind/JsonSerializer.java
@@ -89,6 +89,20 @@
throw new UnsupportedOperationException();
}
+ /**
+ * Mutant factory method that is called if contextual configuration indicates that
+ * a specific filter (as specified by <code>filterId</code>) is to be used for
+ * serialization.
+ *<p>
+ * Default implementation simply returns <code>this</code>; sub-classes that do support
+ * filtering will need to create and return new instance if filter changes.
+ *
+ * @since 2.6
+ */
+ public JsonSerializer<?> withFilterId(Object filterId) {
+ return this;
+ }
+
/*
/**********************************************************
/* Serialization methods
diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializer.java
index 935a650..5298e96 100644
--- a/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializer.java
+++ b/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializer.java
@@ -94,7 +94,7 @@
}
@Override
- protected BeanSerializerBase withFilterId(Object filterId) {
+ public BeanSerializerBase withFilterId(Object filterId) {
return new BeanSerializer(this, _objectIdWriter, filterId);
}
diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/BeanAsArraySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/BeanAsArraySerializer.java
index 9899601..3d75620 100644
--- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/BeanAsArraySerializer.java
+++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/BeanAsArraySerializer.java
@@ -99,7 +99,7 @@
}
@Override
- protected BeanSerializerBase withFilterId(Object filterId) {
+ public BeanSerializerBase withFilterId(Object filterId) {
return new BeanAsArraySerializer(this, _objectIdWriter, filterId);
}
diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnwrappingBeanSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnwrappingBeanSerializer.java
index dd209b7..24dad0e 100644
--- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnwrappingBeanSerializer.java
+++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnwrappingBeanSerializer.java
@@ -76,7 +76,7 @@
}
@Override
- protected BeanSerializerBase withFilterId(Object filterId) {
+ public BeanSerializerBase withFilterId(Object filterId) {
return new UnwrappingBeanSerializer(this, _objectIdWriter, filterId);
}
diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java
index b4a8791..93f0255 100644
--- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java
+++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java
@@ -226,7 +226,8 @@
*
* @since 2.3
*/
- protected abstract BeanSerializerBase withFilterId(Object filterId);
+ @Override
+ public abstract BeanSerializerBase withFilterId(Object filterId);
/**
* Copy-constructor that is useful for sub-classes that just want to
diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java
index 232a504..148505f 100644
--- a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java
+++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java
@@ -237,9 +237,7 @@
return ser;
}
- /**
- * @since 2.3
- */
+ @Override
public MapSerializer withFilterId(Object filterId) {
if (_filterId == filterId) {
return this;
@@ -376,7 +374,7 @@
mser = mser.withContentInclusion(suppressableValue);
}
- // [Issue#307]: allow filtering
+ // [databind#307]: allow filtering
if (property != null) {
AnnotatedMember m = property.getMember();
if (m != null) {