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

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

commit d597a019bd5e76ab56e86a4f9980bb77954c3ab1
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                                      | 2 +-
 .../main/java/org/apache/olingo/odata2/core/commons/Encoder.java   | 6 ++----
 .../java/org/apache/olingo/odata2/core/edm/EdmDateTimeOffset.java  | 7 +++++++
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/odata2-lib/odata-core/pom.xml b/odata2-lib/odata-core/pom.xml
index dad0d1c..9e803d2 100644
--- a/odata2-lib/odata-core/pom.xml
+++ b/odata2-lib/odata-core/pom.xml
@@ -88,7 +88,7 @@
                                        </instructions>
                                </configuration>
                        </plugin>
-               </plugins>
+    </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