diff options
author | Tatu Saloranta <tatu.saloranta@iki.fi> | 2020-07-24 14:41:54 -0700 |
---|---|---|
committer | Tatu Saloranta <tatu.saloranta@iki.fi> | 2020-07-24 14:41:54 -0700 |
commit | 12f9afead2423a3858d424f7804329ea34e5362f (patch) | |
tree | df1ca250aab4b540593ce4eb32cc07da54d06d21 | |
parent | c0cbeb31f7bb5d332a39423696b5ceaa3bf92f2a (diff) | |
download | jackson-databind-12f9afead2423a3858d424f7804329ea34e5362f.tar.gz |
More refactoring (rename, add config param; deprecate)
9 files changed, 75 insertions, 52 deletions
diff --git a/src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java b/src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java index ba422e814..eb59bfb3d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java +++ b/src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java @@ -247,25 +247,6 @@ public abstract class AnnotationIntrospector } /** - * Method for finding information about properties to ignore either by - * name, or by more general specification ("ignore all unknown"). - * This method combines multiple aspects of ignorals and deprecates - * earlier methods such as - * {@link #findPropertiesToIgnore(Annotated, boolean)} and - * {@link #findIgnoreUnknownProperties(AnnotatedClass)}. - * - * @param ac Annotated class to introspect - * - * @since 2.8 - */ - public JsonIgnoreProperties.Value findPropertyIgnorals(Annotated ac) - { - // 18-Oct-2016, tatu: Used to call deprecated methods for backwards - // compatibility in 2.8, but not any more in 2.9 - return JsonIgnoreProperties.Value.empty(); - } - - /** * Method for checking whether properties that have specified type * (class, not generics aware) should be completely ignored for * serialization and deserialization purposes. @@ -279,16 +260,36 @@ public abstract class AnnotationIntrospector public Boolean isIgnorableType(AnnotatedClass ac) { return null; } /** + * Method for finding information about properties to ignore either by + * name, or by more general specification ("ignore all unknown"). + * This method combines multiple aspects of ignorals and deprecates + * earlier methods such as + * {@link #findPropertiesToIgnore(Annotated, boolean)} and + * {@link #findIgnoreUnknownProperties(AnnotatedClass)}. + * + * @param config Configuration settings in effect (for serialization or deserialization) + * @param ann Annotated entity (Class, Accessor) to introspect + * + * @since 2.12 (to replace {@code findPropertyIgnorals()}) + */ + public JsonIgnoreProperties.Value findPropertyIgnoralByName(MapperConfig<?> config, Annotated ann) + { + // In 2.12, remove redirection in future + return findPropertyIgnorals(ann); + } + + /** * Method for finding information about names of properties to included. * This is typically used to strictly limit properties to include based * on fully defined set of names ("allow-listing"), as opposed to excluding * potential properties by exclusion ("deny-listing"). * - * @param ac Annotated entity (Class, acccessor) to introspect + * @param config Configuration settings in effect (for serialization or deserialization) + * @param ann Annotated entity (Class, Accessor) to introspect * * @since 2.12 */ - public JsonIncludeProperties.Value findPropertyInclusionByName(MapperConfig<?> config, Annotated ac) { + public JsonIncludeProperties.Value findPropertyInclusionByName(MapperConfig<?> config, Annotated ann) { return JsonIncludeProperties.Value.all(); } @@ -342,7 +343,7 @@ public abstract class AnnotationIntrospector * * @since 2.6 * - * @deprecated Since 2.8, use {@link #findPropertyIgnorals} instead + * @deprecated Since 2.8, use {@link #findPropertyIgnoralByName} instead */ @Deprecated // since 2.8 public String[] findPropertiesToIgnore(Annotated ac, boolean forSerialization) { @@ -357,11 +358,20 @@ public abstract class AnnotationIntrospector * * @return True if class has something indicating "ignore [all] unknown properties" * - * @deprecated Since 2.8, use {@link #findPropertyIgnorals} instead + * @deprecated Since 2.8, use {@link #findPropertyIgnoralByName} instead */ @Deprecated // since 2.8 public Boolean findIgnoreUnknownProperties(AnnotatedClass ac) { return null; } - + + /** + * @since 2.8 + * @deprecated 2.12 + */ + @Deprecated // since 2.12 + public JsonIgnoreProperties.Value findPropertyIgnorals(Annotated ac) { + return JsonIgnoreProperties.Value.empty(); + } + /* /********************************************************** /* Property auto-detection diff --git a/src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfigBase.java b/src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfigBase.java index da7718a94..5e6d66599 100644 --- a/src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfigBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfigBase.java @@ -660,7 +660,7 @@ public abstract class MapperConfigBase<CFG extends ConfigFeature, { AnnotationIntrospector intr = getAnnotationIntrospector(); JsonIgnoreProperties.Value base = (intr == null) ? null - : intr.findPropertyIgnorals(actualClass); + : intr.findPropertyIgnoralByName(this, actualClass); JsonIgnoreProperties.Value overrides = getDefaultPropertyIgnorals(baseType); return JsonIgnoreProperties.Value.merge(base, overrides); } diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java index b2b84aa79..87b05c90c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java @@ -789,7 +789,8 @@ public abstract class BeanDeserializerBase } // And possibly add more properties to ignore if (accessor != null) { - JsonIgnoreProperties.Value ignorals = intr.findPropertyIgnorals(accessor); + final DeserializationConfig config = ctxt.getConfig(); + JsonIgnoreProperties.Value ignorals = intr.findPropertyIgnoralByName(config, accessor); if (ignorals != null) { Set<String> ignored = ignorals.findIgnoredForDeserialization(); if (!ignored.isEmpty()) { @@ -808,7 +809,7 @@ public abstract class BeanDeserializerBase contextual = contextual.withIgnoreAllUnknown(true); } } - JsonIncludeProperties.Value inclusions = intr.findPropertyInclusionByName(ctxt.getConfig(), accessor); + JsonIncludeProperties.Value inclusions = intr.findPropertyInclusionByName(config, accessor); if (inclusions != null) { Set<String> included = inclusions.getIncluded(); Set<String> prev = contextual._includableProps; diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/MapDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/MapDeserializer.java index 3d978f4b6..261175047 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/std/MapDeserializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/MapDeserializer.java @@ -310,7 +310,8 @@ public class MapDeserializer if (_neitherNull(intr, property)) { AnnotatedMember member = property.getMember(); if (member != null) { - JsonIgnoreProperties.Value ignorals = intr.findPropertyIgnorals(member); + final DeserializationConfig config = ctxt.getConfig(); + JsonIgnoreProperties.Value ignorals = intr.findPropertyIgnoralByName(config, member); if (ignorals != null) { Set<String> ignoresToAdd = ignorals.findIgnoredForDeserialization(); if (!ignoresToAdd.isEmpty()) { @@ -320,7 +321,7 @@ public class MapDeserializer } } } - JsonIncludeProperties.Value inclusions = intr.findPropertyInclusionByName(ctxt.getConfig(), member); + JsonIncludeProperties.Value inclusions = intr.findPropertyInclusionByName(config, member); if (inclusions != null) { Set<String> includedToAdd = inclusions.getIncluded(); if (includedToAdd != null) { diff --git a/src/main/java/com/fasterxml/jackson/databind/introspect/AnnotationIntrospectorPair.java b/src/main/java/com/fasterxml/jackson/databind/introspect/AnnotationIntrospectorPair.java index 9aa1691eb..ad67b7abf 100644 --- a/src/main/java/com/fasterxml/jackson/databind/introspect/AnnotationIntrospectorPair.java +++ b/src/main/java/com/fasterxml/jackson/databind/introspect/AnnotationIntrospectorPair.java @@ -117,15 +117,16 @@ public class AnnotationIntrospectorPair return (name2 == null) ? name1 : name2; } + // since 2.12 @Override - public JsonIgnoreProperties.Value findPropertyIgnorals(Annotated a) + public JsonIgnoreProperties.Value findPropertyIgnoralByName(MapperConfig<?> config, Annotated ann) { - JsonIgnoreProperties.Value v2 = _secondary.findPropertyIgnorals(a); - JsonIgnoreProperties.Value v1 = _primary.findPropertyIgnorals(a); + JsonIgnoreProperties.Value v2 = _secondary.findPropertyIgnoralByName(config, ann); + JsonIgnoreProperties.Value v1 = _primary.findPropertyIgnoralByName(config, ann); return (v2 == null) // shouldn't occur but ? v1 : v2.withOverrides(v1); } - + @Override public JsonIncludeProperties.Value findPropertyInclusionByName(MapperConfig<?> config, Annotated a) { @@ -193,7 +194,16 @@ public class AnnotationIntrospectorPair result = _secondary.findIgnoreUnknownProperties(ac); } return result; - } + } + + @Override + public JsonIgnoreProperties.Value findPropertyIgnorals(Annotated a) + { + JsonIgnoreProperties.Value v2 = _secondary.findPropertyIgnorals(a); + JsonIgnoreProperties.Value v1 = _primary.findPropertyIgnorals(a); + return (v2 == null) // shouldn't occur but + ? v1 : v2.withOverrides(v1); + } /* /****************************************************** diff --git a/src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java b/src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java index 9706858d5..c5aa53d14 100644 --- a/src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java +++ b/src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java @@ -292,8 +292,14 @@ public class JacksonAnnotationIntrospector return PropertyName.construct(ann.value(), ns); } - @Override // since 2.8 - public JsonIgnoreProperties.Value findPropertyIgnorals(Annotated a) + @Override + public Boolean isIgnorableType(AnnotatedClass ac) { + JsonIgnoreType ignore = _findAnnotation(ac, JsonIgnoreType.class); + return (ignore == null) ? null : ignore.value(); + } + + @Override // since 2.12 + public JsonIgnoreProperties.Value findPropertyIgnoralByName(MapperConfig<?> config, Annotated a) { JsonIgnoreProperties v = _findAnnotation(a, JsonIgnoreProperties.class); if (v == null) { @@ -303,12 +309,6 @@ public class JacksonAnnotationIntrospector } @Override - public Boolean isIgnorableType(AnnotatedClass ac) { - JsonIgnoreType ignore = _findAnnotation(ac, JsonIgnoreType.class); - return (ignore == null) ? null : ignore.value(); - } - - @Override public JsonIncludeProperties.Value findPropertyInclusionByName(MapperConfig<?> config, Annotated a) { JsonIncludeProperties v = _findAnnotation(a, JsonIncludeProperties.class); 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 31aa78b91..545cd94e5 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 @@ -504,7 +504,7 @@ public abstract class BeanSerializerBase // Then we may have an override for Object Id if (accessor != null) { - JsonIgnoreProperties.Value ignorals = intr.findPropertyIgnorals(accessor); + JsonIgnoreProperties.Value ignorals = intr.findPropertyIgnoralByName(config, accessor); if (ignorals != null) { ignoredProps = ignorals.findIgnoredForSerialization(); } 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 2711bf92c..4ebd088d0 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 @@ -506,8 +506,9 @@ public class MapSerializer Set<String> included = _includedEntries; boolean sortKeys = false; if (_neitherNull(propertyAcc, intr)) { + final SerializationConfig config = provider.getConfig(); // ignorals - JsonIgnoreProperties.Value ignorals = intr.findPropertyIgnorals(propertyAcc); + JsonIgnoreProperties.Value ignorals = intr.findPropertyIgnoralByName(config, propertyAcc); if (ignorals != null){ Set<String> newIgnored = ignorals.findIgnoredForSerialization(); if (_nonEmpty(newIgnored)) { @@ -518,7 +519,7 @@ public class MapSerializer } } // inclusions - JsonIncludeProperties.Value inclusions = intr.findPropertyInclusionByName(provider.getConfig(), propertyAcc); + JsonIncludeProperties.Value inclusions = intr.findPropertyInclusionByName(config, propertyAcc); if (inclusions != null) { Set<String> newIncluded = inclusions.getIncluded(); if (newIncluded != null) { diff --git a/src/test/java/com/fasterxml/jackson/databind/introspect/IntrospectorPairTest.java b/src/test/java/com/fasterxml/jackson/databind/introspect/IntrospectorPairTest.java index a862713a7..16f1be8a1 100644 --- a/src/test/java/com/fasterxml/jackson/databind/introspect/IntrospectorPairTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/introspect/IntrospectorPairTest.java @@ -119,8 +119,8 @@ public class IntrospectorPairTest extends BaseMapTest } @Override - public JsonIgnoreProperties.Value findPropertyIgnorals(Annotated a) { - return (JsonIgnoreProperties.Value) values.get("findPropertyIgnorals"); + public JsonIgnoreProperties.Value findPropertyIgnoralByName(MapperConfig<?> config, Annotated a) { + return (JsonIgnoreProperties.Value) values.get("findPropertyIgnoralByName"); } @Override @@ -285,14 +285,14 @@ public class IntrospectorPairTest extends BaseMapTest { JsonIgnoreProperties.Value incl = JsonIgnoreProperties.Value.forIgnoredProperties("foo"); IntrospectorWithMap intr = new IntrospectorWithMap() - .add("findPropertyIgnorals", incl); + .add("findPropertyIgnoralByName", incl); IntrospectorWithMap intrEmpty = new IntrospectorWithMap() - .add("findPropertyIgnorals", JsonIgnoreProperties.Value.empty()); + .add("findPropertyIgnoralByName", JsonIgnoreProperties.Value.empty()); assertEquals(JsonIgnoreProperties.Value.empty(), - new AnnotationIntrospectorPair(intrEmpty, intrEmpty).findPropertyIgnorals(null)); + new AnnotationIntrospectorPair(intrEmpty, intrEmpty).findPropertyIgnoralByName(null, null)); // should actually verify inclusion combining, but there are separate tests for that - assertEquals(incl, new AnnotationIntrospectorPair(intrEmpty, intr).findPropertyIgnorals(null)); - assertEquals(incl, new AnnotationIntrospectorPair(intr, intrEmpty).findPropertyIgnorals(null)); + assertEquals(incl, new AnnotationIntrospectorPair(intrEmpty, intr).findPropertyIgnoralByName(null, null)); + assertEquals(incl, new AnnotationIntrospectorPair(intr, intrEmpty).findPropertyIgnoralByName(null, null)); } public void testIsIgnorableType() throws Exception |