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

mibo pushed a commit to branch pr-14
in repository https://gitbox.apache.org/repos/asf/olingo-odata2.git

commit 93659af1b42abd11c80c69a1b370fbc13b274711
Author: Song Yihan <[email protected]>
AuthorDate: Wed Jan 24 11:35:28 2018 +0800

    [OLINGO-1219] Add support for Instant type
    
    Instant type is widely used in Java 8, need to support it
---
 odata2-lib/odata-core/pom.xml                                  | 10 +++++++++-
 .../java/org/apache/olingo/odata2/core/commons/Encoder.java    |  6 ++----
 .../org/apache/olingo/odata2/core/edm/EdmDateTimeOffset.java   |  7 +++++++
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/odata2-lib/odata-core/pom.xml b/odata2-lib/odata-core/pom.xml
index dad0d1c..a115e37 100644
--- a/odata2-lib/odata-core/pom.xml
+++ b/odata2-lib/odata-core/pom.xml
@@ -88,7 +88,15 @@
                                        </instructions>
                                </configuration>
                        </plugin>
-               </plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>8</source>
+          <target>8</target>
+        </configuration>
+      </plugin>
+    </plugins>
        </build>
 
        <profiles>
diff --git 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/Encoder.java
 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/Encoder.java
index 478b83c..181cbd7 100644
--- 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/Encoder.java
+++ 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/Encoder.java
@@ -95,13 +95,11 @@ public class Encoder {
    * @return encoded representation
    */
   private String encodeInternal(final String input) {
-    StringBuilder resultStr = new StringBuilder();
-    
-    // avoid NPE if the given input is null
     if (input == null) {
         return null;
     }
-    
+
+    StringBuilder resultStr = new StringBuilder();
     try {
       for (byte utf8Byte : input.getBytes("UTF-8")) {
         final char character = (char) utf8Byte;
diff --git 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmDateTimeOffset.java
 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmDateTimeOffset.java
index 07695eb..86378a7 100644
--- 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmDateTimeOffset.java
+++ 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmDateTimeOffset.java
@@ -19,6 +19,7 @@
 package org.apache.olingo.odata2.core.edm;
 
 import java.sql.Timestamp;
+import java.time.Instant;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.TimeZone;
@@ -150,6 +151,12 @@ public class EdmDateTimeOffset extends AbstractSimpleType {
       milliSeconds = dateTimeValue.getTimeInMillis();
     } else if (value instanceof Long) {
       milliSeconds = (Long) value;
+    } else if (value instanceof Instant) {
+      try {
+        milliSeconds = ((Instant) value).toEpochMilli();
+      } catch (ArithmeticException e) { // in case the Instant is far away 
from epoch
+        milliSeconds = Long.MAX_VALUE;
+      }
     } else {
       throw new 
EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass()));
     }

Reply via email to