You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/10/09 15:07:48 UTC

[isis] 02/02: ISIS-1972: applib: add JAXB XmlAdapters for Java built-in temporal types

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 876d754e26510f7d65cf6d73b7d5e78024f9bc81
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Oct 9 17:07:39 2018 +0200

    ISIS-1972: applib: add JAXB XmlAdapters for Java built-in temporal types
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-1972
---
 .../apache/isis/applib/adapters/JaxbAdapters.java  | 106 +++++++++++++++++++++
 1 file changed, 106 insertions(+)

diff --git a/core/applib/src/main/java/org/apache/isis/applib/adapters/JaxbAdapters.java b/core/applib/src/main/java/org/apache/isis/applib/adapters/JaxbAdapters.java
new file mode 100644
index 0000000..c4219cf
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/adapters/JaxbAdapters.java
@@ -0,0 +1,106 @@
+/*
+ *  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.isis.applib.adapters;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.OffsetDateTime;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+/**
+ * Provides JAXB XmlAdapters for Java built-in temporal types. 
+ * 
+ * @since 2.0.0-M2
+ */
+public final class JaxbAdapters {
+
+    public static final class DateAdapter extends XmlAdapter<String, java.util.Date>{
+
+        public java.util.Date unmarshal(String v) throws Exception {
+            return new java.util.Date(Long.parseLong(v));
+        }
+
+        public String marshal(java.util.Date v) throws Exception {
+            return Long.toString(v.getTime());
+        }
+
+    }
+    
+    public static final class SqlDateAdapter extends XmlAdapter<String, java.sql.Date>{
+
+        public java.sql.Date unmarshal(String v) throws Exception {
+            return java.sql.Date.valueOf(v);
+        }
+
+        public String marshal(java.sql.Date v) throws Exception {
+            return v.toString();
+        }
+
+    }
+    
+    public static final class SqlTimestampAdapter extends XmlAdapter<String, java.sql.Timestamp>{
+
+        public java.sql.Timestamp unmarshal(String v) throws Exception {
+            return new java.sql.Timestamp(Long.parseLong(v));
+        }
+
+        public String marshal(java.sql.Timestamp v) throws Exception {
+            return Long.toString(v.getTime());
+        }
+
+    }
+    
+    public static final class LocalDateAdapter extends XmlAdapter<String, LocalDate>{
+
+        public LocalDate unmarshal(String v) throws Exception {
+            return LocalDate.parse(v);
+        }
+
+        public String marshal(LocalDate v) throws Exception {
+            return v.toString();
+        }
+
+    }
+
+    public static final class LocalDateTimeAdapter extends XmlAdapter<String, LocalDateTime>{
+
+        public LocalDateTime unmarshal(String v) throws Exception {
+            return LocalDateTime.parse(v);
+        }
+
+        public String marshal(LocalDateTime v) throws Exception {
+            return v.toString();
+        }
+
+    }
+
+    public static final class OffsetDateTimeAdapter extends XmlAdapter<String, OffsetDateTime>{
+
+        public OffsetDateTime unmarshal(String v) throws Exception {
+            return OffsetDateTime.parse(v);
+        }
+
+        public String marshal(OffsetDateTime v) throws Exception {
+            return v.toString();
+        }
+
+    }
+    
+}