cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cxf git commit: [CXF-7441] Type from extended XmlAdapter isn't resolved correctly
Date Mon, 10 Jul 2017 18:24:35 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 7fa9a0a0a -> 1a45914bc


[CXF-7441] Type from extended XmlAdapter isn't resolved correctly


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/1a45914b
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/1a45914b
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/1a45914b

Branch: refs/heads/master
Commit: 1a45914bca678b4be3c52a8c2f2a479aae7b8347
Parents: 7fa9a0a
Author: Dennis Kieselhorst <deki@apache.org>
Authored: Mon Jul 10 20:24:17 2017 +0200
Committer: Dennis Kieselhorst <deki@apache.org>
Committed: Mon Jul 10 20:24:17 2017 +0200

----------------------------------------------------------------------
 rt/frontend/jaxrs/pom.xml                       |  8 +-
 .../org/apache/cxf/jaxrs/utils/JAXBUtils.java   | 11 ++-
 .../apache/cxf/jaxrs/utils/JAXBUtilsTest.java   | 96 ++++++++++++++++++++
 3 files changed, 113 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/1a45914b/rt/frontend/jaxrs/pom.xml
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/pom.xml b/rt/frontend/jaxrs/pom.xml
index acdb52a..d24e003 100644
--- a/rt/frontend/jaxrs/pom.xml
+++ b/rt/frontend/jaxrs/pom.xml
@@ -173,7 +173,13 @@
                     <artifactId>cxf-rt-frontend-simple</artifactId>
                 </exclusion>
             </exclusions>
-        </dependency> 
+        </dependency>
+        <dependency>
+            <groupId>com.migesok</groupId>
+            <artifactId>jaxb-java-time-adapters</artifactId>
+            <version>1.1.3</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
     <build>
         <pluginManagement>

http://git-wip-us.apache.org/repos/asf/cxf/blob/1a45914b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java
index 8e29a32..e505d27 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java
@@ -89,7 +89,16 @@ public final class JAXBUtils {
             if (adapter.type() != XmlJavaTypeAdapter.DEFAULT.class) {
                 theType = adapter.type();
             } else {
-                Type[] types = InjectionUtils.getActualTypes(adapter.value().getGenericSuperclass());
+                Type topAdapterType = adapter.value().getGenericSuperclass();
+                Class<?> superClass = adapter.value().getSuperclass();
+                while (superClass != null) {
+                    Class<?> nextSuperClass = superClass.getSuperclass();
+                    if (nextSuperClass != null && !Object.class.equals(nextSuperClass))
{
+                        topAdapterType = superClass.getGenericSuperclass();
+                    }
+                    superClass = nextSuperClass;
+                }
+                Type[] types = InjectionUtils.getActualTypes(topAdapterType);
                 if (types != null && types.length == 2) {
                     int index = boundType ? 1 : 0;
                     theType = InjectionUtils.getActualType(types[index]);

http://git-wip-us.apache.org/repos/asf/cxf/blob/1a45914b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXBUtilsTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXBUtilsTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXBUtilsTest.java
new file mode 100644
index 0000000..61a5aef
--- /dev/null
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXBUtilsTest.java
@@ -0,0 +1,96 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.jaxrs.utils;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.QueryParam;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+import com.migesok.jaxb.adapter.javatime.LocalDateXmlAdapter;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class JAXBUtilsTest {
+
+    @Test
+    public void simpleXmlJavaTypeAdapter() {
+        correctValueType(CustomerDetailsWithSimpleAdapter.class);
+    }
+
+    @Test
+    public void extendedXmlJavaTypeAdapter() {
+        correctValueType(CustomerDetailsWithExtendedAdapter.class);
+    }
+
+    private void correctValueType(Class<?> clazz) {
+        Field field = clazz.getDeclaredFields()[0];
+        Annotation[] paramAnns = field.getDeclaredAnnotations();
+        Class valueType = JAXBUtils.getValueTypeFromAdapter(LocalDate.class, LocalDate.class,
paramAnns);
+        Assert.assertEquals(String.class, valueType);
+    }
+
+    public class CustomerDetailsWithExtendedAdapter {
+        @NotNull
+        @QueryParam("birthDate")
+        @XmlJavaTypeAdapter(LocalDateXmlAdapter.class)
+        private LocalDate birthDate;
+
+        public LocalDate getBirthDate() {
+            return birthDate;
+        }
+
+        public void setBirthDate(LocalDate birthDate) {
+            this.birthDate = birthDate;
+        }
+    }
+
+    public class CustomerDetailsWithSimpleAdapter {
+        @NotNull
+        @QueryParam("birthDate")
+        @XmlJavaTypeAdapter(LocalDateAdapter.class)
+        private LocalDate birthDate;
+
+        public LocalDate getBirthDate() {
+            return birthDate;
+        }
+
+        public void setBirthDate(LocalDate birthDate) {
+            this.birthDate = birthDate;
+        }
+    }
+
+    public class LocalDateAdapter extends XmlAdapter<String, LocalDate> {
+        @Override
+        public LocalDate unmarshal(String dateInput) {
+            return LocalDate.parse(dateInput);
+        }
+
+        @Override
+        public String marshal(LocalDate localDate) {
+            return DateTimeFormatter.ISO_DATE.format(localDate);
+        }
+    }
+}


Mime
View raw message