cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [cxf] branch 3.1.x-fixes updated: [CXF-7515] fix and testcase for classes in default package
Date Mon, 25 Sep 2017 12:21:26 GMT
This is an automated email from the ASF dual-hosted git repository.

deki pushed a commit to branch 3.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/3.1.x-fixes by this push:
     new 4115105  [CXF-7515] fix and testcase for classes in default package
4115105 is described below

commit 41151051f82f4b8ac2a2f3c51a081a7cdafaa562
Author: Dennis Kieselhorst <deki@apache.org>
AuthorDate: Mon Sep 25 14:09:34 2017 +0200

    [CXF-7515] fix and testcase for classes in default package
---
 .../src/main/java/org/apache/cxf/jaxb/Utils.java   | 15 ++++++----
 .../src/test/java/SampleClassInDefaultPackage.java | 34 ++++++++++++++++++++++
 .../org/apache/cxf/jaxb/JAXBDataBindingTest.java   | 11 +++++++
 3 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Utils.java b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Utils.java
index 40de666..3899f50 100644
--- a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Utils.java
+++ b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Utils.java
@@ -291,12 +291,15 @@ final class Utils {
             adapter = m.getReturnType().getAnnotation(XmlJavaTypeAdapter.class);
         }
         if (adapter == null) {
-            XmlJavaTypeAdapters adapters = m.getDeclaringClass().getPackage().getAnnotation(XmlJavaTypeAdapters.class);
-            if (adapters != null) {
-                for (XmlJavaTypeAdapter candidate : adapters.value()) {
-                    if (candidate != null && candidate.type().equals(m.getGenericReturnType()))
{
-                        adapter = candidate;
-                        break;
+            Package packageDeclaration = m.getDeclaringClass().getPackage();
+            if (packageDeclaration != null) {
+                XmlJavaTypeAdapters adapters = packageDeclaration.getAnnotation(XmlJavaTypeAdapters.class);
+                if (adapters != null) {
+                    for (XmlJavaTypeAdapter candidate : adapters.value()) {
+                        if (candidate != null && candidate.type().equals(m.getGenericReturnType()))
{
+                            adapter = candidate;
+                            break;
+                        }
                     }
                 }
             }
diff --git a/rt/databinding/jaxb/src/test/java/SampleClassInDefaultPackage.java b/rt/databinding/jaxb/src/test/java/SampleClassInDefaultPackage.java
new file mode 100644
index 0000000..9833fb4
--- /dev/null
+++ b/rt/databinding/jaxb/src/test/java/SampleClassInDefaultPackage.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+//CHECKSTYLE:OFF
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public class SampleClassInDefaultPackage {
+    private String attribute = "test";
+
+    public String getAttribute() {
+        return attribute;
+    }
+
+    public void setAttribute(String attribute) {
+        this.attribute = attribute;
+    }
+}
+//CHECKSTYLE:ON
diff --git a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java
b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java
index 980f2de..e75ada7 100644
--- a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java
+++ b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java
@@ -336,6 +336,17 @@ public class JAXBDataBindingTest extends Assert {
 
     }
 
+    @Test
+    public void testClassInDefaultPackage() throws Exception {
+        Class<?> sampleClassInDefaultPackage = Class.forName("SampleClassInDefaultPackage");
+        Set<Class<?>> classes = new HashSet<>();
+        Collection<Object> typeReferences = new ArrayList<>();
+        Map<String, Object> props = new HashMap<>();
+        JAXBContextInitializer init = new JAXBContextInitializer(null, classes, typeReferences,
props);
+        init.addClass(sampleClassInDefaultPackage);
+        assertEquals(1, classes.size());
+    }
+
     @XmlRootElement
     public static class Person {
         @XmlAttribute

-- 
To stop receiving notification emails like this one, please contact
['"commits@cxf.apache.org" <commits@cxf.apache.org>'].

Mime
View raw message