From 0469ab7c32c5f71a1b65a84ffbaf5920ca99a032 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Mon, 24 Jun 2024 17:46:58 -0700 Subject: [PATCH] Add a test for #4595 --- .../introspect/IntrospectorPairTest.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) 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 0f10bd875c..70d7580b4f 100644 --- a/src/test/java/com/fasterxml/jackson/databind/introspect/IntrospectorPairTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/introspect/IntrospectorPairTest.java @@ -207,6 +207,17 @@ public String findTypeName(AnnotatedClass ac) { return (String) values.get("findTypeName"); } + /* + /****************************************************** + /* General member (field, method/constructor) annotations + /****************************************************** + */ + + @Override + public PropertyName findWrapperName(Annotated ann) { + return (PropertyName) values.get("findWrapperName"); + } + /* /****************************************************** /* Serialization introspection @@ -386,6 +397,42 @@ public void testFindClassDescription() throws Exception // // // 3 deprecated methods, skip + /* + /********************************************************** + /* Test methods, general member annotations + /********************************************************** + */ + + @Test + public void testFindWrapperName() throws Exception + { + final PropertyName NAME_WITH_NS = PropertyName.construct("simple", "ns"); + final PropertyName NAME_NO_NS = PropertyName.construct("other", null); + + assertNull(new AnnotationIntrospectorPair(NO_ANNOTATIONS, NO_ANNOTATIONS) + .findClassDescription(null)); + + // First: basic merging of namespace/localname info + IntrospectorWithMap intr1 = new IntrospectorWithMap() + .add("findWrapperName", NAME_WITH_NS); + IntrospectorWithMap intr2 = new IntrospectorWithMap() + .add("findWrapperName", NAME_NO_NS); + assertSame(NAME_WITH_NS, + new AnnotationIntrospectorPair(intr1, intr2).findWrapperName(null)); + assertEquals(PropertyName.construct("other", "ns"), + new AnnotationIntrospectorPair(intr2, intr1).findWrapperName(null)); + + // [databind#4595]: NO_NAME should be retained, not merged + intr1 = new IntrospectorWithMap() + .add("findWrapperName", PropertyName.NO_NAME); + intr2 = new IntrospectorWithMap() + .add("findWrapperName", NAME_WITH_NS); + assertSame(PropertyName.NO_NAME, + new AnnotationIntrospectorPair(intr1, intr2).findWrapperName(null)); + assertSame(NAME_WITH_NS, + new AnnotationIntrospectorPair(intr2, intr1).findWrapperName(null)); + } + /* /********************************************************** /* Test methods, ser/deser