Merge pull request #212 from willson-chen/feature_java8_time

Feature java8 time
diff --git a/java8_time.go b/java8_time.go
new file mode 100644
index 0000000..d4a72b1
--- /dev/null
+++ b/java8_time.go
@@ -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.
+ */
+
+package hessian
+
+import (
+	"github.com/apache/dubbo-go-hessian2/java8_time"
+)
+
+func init() {
+	RegisterPOJO(&java8_time.Year{Year: 2020})
+	RegisterPOJO(&java8_time.YearMonth{Month: 2020, Year: 6})
+	RegisterPOJO(&java8_time.Period{Years: 2020, Months: 6, Days: 6})
+	RegisterPOJO(&java8_time.LocalDate{Year: 2020, Month: 6, Day: 6})
+	RegisterPOJO(&java8_time.LocalTime{Hour: 6, Minute: 6, Second: 0, Nano: 0})
+	RegisterPOJO(&java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 6}, Time: java8_time.LocalTime{Hour: 6, Minute: 6}})
+	RegisterPOJO(&java8_time.MonthDay{Month: 6, Day: 6})
+	RegisterPOJO(&java8_time.Duration{Second: 0, Nano: 0})
+	RegisterPOJO(&java8_time.Instant{Seconds: 100, Nanos: 0})
+}
diff --git a/java8_time/duration.go b/java8_time/duration.go
new file mode 100644
index 0000000..ee01d54
--- /dev/null
+++ b/java8_time/duration.go
@@ -0,0 +1,31 @@
+/*
+ * 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 java8_time
+
+type Duration struct {
+	Second int64 `hessian:"second"`
+	Nano   int32 `hessian:"nano"`
+}
+
+func (Duration) JavaClassName() string {
+	return "com.alibaba.com.caucho.hessian.io.java8.DurationHandle"
+}
+
+func (Duration) Error() string {
+	return "encode Duration error"
+}
diff --git a/java8_time/instant.go b/java8_time/instant.go
new file mode 100644
index 0000000..09e7cce
--- /dev/null
+++ b/java8_time/instant.go
@@ -0,0 +1,31 @@
+/*
+ * 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 java8_time
+
+type Instant struct {
+	Seconds int64 `hessian:"seconds"`
+	Nanos   int32 `hessian:"nanos"`
+}
+
+func (Instant) JavaClassName() string {
+	return "com.alibaba.com.caucho.hessian.io.java8.InstantHandle"
+}
+
+func (Instant) Error() string {
+	return "encode Instant error"
+}
diff --git a/java8_time/local_date.go b/java8_time/local_date.go
new file mode 100644
index 0000000..e71281e
--- /dev/null
+++ b/java8_time/local_date.go
@@ -0,0 +1,32 @@
+/*
+ * 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 java8_time
+
+type LocalDate struct {
+	Year  int32 `hessian:"year"`
+	Month int32 `hessian:"month"`
+	Day   int32 `hessian:"day"`
+}
+
+func (LocalDate) JavaClassName() string {
+	return "com.alibaba.com.caucho.hessian.io.java8.LocalDateHandle"
+}
+
+func (LocalDate) Error() string {
+	return "encode LocalDate error"
+}
diff --git a/java8_time/local_date_time.go b/java8_time/local_date_time.go
new file mode 100644
index 0000000..2c0c20a
--- /dev/null
+++ b/java8_time/local_date_time.go
@@ -0,0 +1,31 @@
+/*
+ * 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 java8_time
+
+type LocalDateTime struct {
+	Date LocalDate `hessian:"date"`
+	Time LocalTime `hessian:"time"`
+}
+
+func (LocalDateTime) JavaClassName() string {
+	return "com.alibaba.com.caucho.hessian.io.java8.LocalDateTimeHandle"
+}
+
+func (LocalDateTime) Error() string {
+	return "encode LocalDateTime error"
+}
diff --git a/java8_time/local_time.go b/java8_time/local_time.go
new file mode 100644
index 0000000..408e104
--- /dev/null
+++ b/java8_time/local_time.go
@@ -0,0 +1,33 @@
+/*
+ * 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 java8_time
+
+type LocalTime struct {
+	Hour   int32 `hessian:"hour"`
+	Minute int32 `hessian:"minute"`
+	Second int32 `hessian:"second"`
+	Nano   int32 `hessian:"nano"`
+}
+
+func (LocalTime) JavaClassName() string {
+	return "com.alibaba.com.caucho.hessian.io.java8.LocalTimeHandle"
+}
+
+func (LocalTime) Error() string {
+	return "encode LocalTime error"
+}
diff --git a/java8_time/month_day.go b/java8_time/month_day.go
new file mode 100644
index 0000000..0540e61
--- /dev/null
+++ b/java8_time/month_day.go
@@ -0,0 +1,31 @@
+/*
+ * 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 java8_time
+
+type MonthDay struct {
+	Month int32 `hessian:"month"`
+	Day   int32 `hessian:"day"`
+}
+
+func (MonthDay) JavaClassName() string {
+	return "com.alibaba.com.caucho.hessian.io.java8.MonthDayHandle"
+}
+
+func (MonthDay) Error() string {
+	return "encode MonthDay error"
+}
diff --git a/java8_time/period.go b/java8_time/period.go
new file mode 100644
index 0000000..a95df3c
--- /dev/null
+++ b/java8_time/period.go
@@ -0,0 +1,32 @@
+/*
+ * 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 java8_time
+
+//java8-time java.time.Period
+type Period struct {
+	Days   int32 `hessian:"days"`
+	Months int32 `hessian:"months"`
+	Years  int32 `hessian:"years"`
+}
+
+func (Period) JavaClassName() string {
+	return "com.alibaba.com.caucho.hessian.io.java8.PeriodHandle"
+}
+
+func (Period) Error() string {
+	return "encode Period error"
+}
diff --git a/java8_time/year.go b/java8_time/year.go
new file mode 100644
index 0000000..041e242
--- /dev/null
+++ b/java8_time/year.go
@@ -0,0 +1,30 @@
+/*
+ * 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 java8_time
+
+//java8-time java.time.Year
+type Year struct {
+	Year int32 `hessian:"year"`
+}
+
+func (Year) JavaClassName() string {
+	return "com.alibaba.com.caucho.hessian.io.java8.YearHandle"
+}
+
+func (Year) Error() string {
+	return "encode Year error"
+}
diff --git a/java8_time/year_month.go b/java8_time/year_month.go
new file mode 100644
index 0000000..3f07a13
--- /dev/null
+++ b/java8_time/year_month.go
@@ -0,0 +1,31 @@
+/*
+ * 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 java8_time
+
+//java8-time java.time.YearMonth
+type YearMonth struct {
+	Month int32 `hessian:"month"`
+	Year  int32 `hessian:"year"`
+}
+
+func (YearMonth) JavaClassName() string {
+	return "com.alibaba.com.caucho.hessian.io.java8.YearMonthHandle"
+}
+
+func (YearMonth) Error() string {
+	return "encode YearMonth error"
+}
diff --git a/java8_time_test.go b/java8_time_test.go
new file mode 100644
index 0000000..7506291
--- /dev/null
+++ b/java8_time_test.go
@@ -0,0 +1,39 @@
+/*
+ * 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 hessian
+
+import (
+	"github.com/apache/dubbo-go-hessian2/java8_time"
+	"testing"
+)
+
+func TestJava8Time(t *testing.T) {
+	doTestTime(t, "java8_Year", &java8_time.Year{Year: 2020})
+	doTestTime(t, "java8_LocalDate", &java8_time.LocalDate{Year: 2020, Month: 6, Day: 6})
+	doTestTime(t, "java8_LocalTime", &java8_time.LocalTime{Hour: 6, Minute: 6})
+	doTestTime(t, "java8_LocalDateTime", &java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 6}, Time: java8_time.LocalTime{Hour: 6, Minute: 6}})
+	doTestTime(t, "java8_MonthDay", &java8_time.MonthDay{Month: 6, Day: 6})
+	doTestTime(t, "java8_Duration", &java8_time.Duration{Second: 0, Nano: 0})
+	doTestTime(t, "java8_Instant", &java8_time.Instant{Seconds: 100, Nanos: 0})
+	doTestTime(t, "java8_YearMonth", &java8_time.YearMonth{Year: 2020, Month: 6})
+	doTestTime(t, "java8_Period", &java8_time.Period{Years: 2020, Months: 6, Days: 6})
+}
+
+func doTestTime(t *testing.T, method string, expected interface{}) {
+	testDecodeFramework(t, method, expected)
+}
diff --git a/test_hessian/src/main/java/test/Hessian.java b/test_hessian/src/main/java/test/Hessian.java
index b954541..f26cbed 100644
--- a/test_hessian/src/main/java/test/Hessian.java
+++ b/test_hessian/src/main/java/test/Hessian.java
@@ -62,6 +62,15 @@
             Hessian2Output output = new Hessian2Output(System.out);
             output.writeObject(object);
             output.flush();
+        }else if(args[0].startsWith("java8_")){
+            //add java8 java.time Object test
+            Method method = TestJava8Time.class.getMethod(args[0]);
+            Object obj = new Object();
+            Object object =method.invoke(obj);
+
+            Hessian2Output output = new Hessian2Output(System.out);
+            output.writeObject(object);
+            output.flush();
         }
     }
 
diff --git a/test_hessian/src/main/java/test/TestJava8Time.java b/test_hessian/src/main/java/test/TestJava8Time.java
new file mode 100644
index 0000000..a4e39f0
--- /dev/null
+++ b/test_hessian/src/main/java/test/TestJava8Time.java
@@ -0,0 +1,81 @@
+/*
+ * 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 test;
+
+import java.time.*;
+
+public class TestJava8Time {
+
+    public static Duration java8_Duration() {
+        return Duration.ZERO;
+    }
+
+    public static Instant java8_Instant() {
+        return Instant.ofEpochMilli(100000L);
+    }
+
+    public static LocalDate java8_LocalDate() {
+        return LocalDate.of(2020, 6, 6);
+    }
+
+    public static LocalDateTime java8_LocalDateTime() {
+        return LocalDateTime.of(2020, 6, 6, 6, 6);
+    }
+
+    public static LocalTime java8_LocalTime() {
+        return LocalTime.of(6, 6);
+    }
+
+    public static MonthDay java8_MonthDay() {
+        return MonthDay.of(6, 6);
+    }
+
+    public static OffsetDateTime java8_OffsetDateTime() {
+        return OffsetDateTime.of(2020, 6, 6, 6, 6, 6, 6, ZoneOffset.MIN);
+    }
+
+    public static OffsetTime java8_OffsetTime() {
+        return OffsetTime.of(6, 6, 6, 6, ZoneOffset.MIN);
+    }
+
+    public static Period java8_Period() {
+        return Period.of(2020, 6, 6);
+    }
+
+    public static Year java8_Year() {
+        return Year.of(2020);
+    }
+
+    public static YearMonth java8_YearMonth() {
+        return YearMonth.of(2020, 6);
+    }
+
+    public static ZonedDateTime java8_ZonedDateTime() {
+        ZonedDateTime of = ZonedDateTime.of(java8_LocalDateTime(), java8_ZoneId());
+        return of;
+    }
+
+    public static ZoneId java8_ZoneId() {
+        return ZoneId.of("1000");
+    }
+
+    public static ZoneOffset java8_ZoneOffset() {
+        return ZoneOffset.of("1000");
+    }
+
+}