Repository: apache/dubbo-go-hessian2
Pull request #235 (2020-09-09 00:39:55)

Release v1.7.0 RC2
<!--  Thanks for sending a pull request! 
-->

**What this PR does**:
add bug fix into v1.7.0 

**Which issue(s) this PR fixes**:

Fixes [fix fields name mismatch in Duration class](https://github.com/apache/dubbo-go-hessian2/pull/234)




Patch:
diff --git a/CHANGE.md b/CHANGE.md
index 2690398..21dc763 100644
--- a/CHANGE.md
+++ b/CHANGE.md
@@ -16,6 +16,7 @@
 - fix eunm encode error in request. [#203](https://github.com/apache/dubbo-go-hessian2/pull/203)
 - fix []byte field decoding issue. [#216](https://github.com/apache/dubbo-go-hessian2/pull/216)
 - fix decoding error for map in map. [#229](https://github.com/apache/dubbo-go-hessian2/pull/229)
+- fix fields name mismatch in Duration class. [#234](https://github.com/apache/dubbo-go-hessian2/pull/234)
 
 ## v1.6.0
 
diff --git a/java8_time.go b/java8_time.go
index 6d5283f..2b80121 100644
--- a/java8_time.go
+++ b/java8_time.go
@@ -24,16 +24,16 @@ import (
 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, Second: 6, Nano: 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})
-	RegisterPOJO(&java8_time.ZoneOffSet{Seconds: 0})
-	RegisterPOJO(&java8_time.OffsetDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 6}, Time: java8_time.LocalTime{Hour: 6, Minute: 6, Second: 6, Nano: 6}}, Offset: java8_time.ZoneOffSet{Seconds: -64800}})
-	RegisterPOJO(&java8_time.OffsetTime{LocalTime: java8_time.LocalTime{Hour: 6, Minute: 6, Second: 6, Nano: 6}, ZoneOffset: java8_time.ZoneOffSet{Seconds: -64800}})
-	RegisterPOJO(&java8_time.ZonedDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 6}, Time: java8_time.LocalTime{Hour: 6, Minute: 6, Second: 6, Nano: 6}}, Offset: java8_time.ZoneOffSet{Seconds: 0}, ZoneId: "Z"})
+	RegisterPOJO(&java8_time.Period{Years: 2020, Months: 6, Days: 16})
+	RegisterPOJO(&java8_time.LocalDate{Year: 2020, Month: 6, Day: 16})
+	RegisterPOJO(&java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3})
+	RegisterPOJO(&java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 16}, Time: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}})
+	RegisterPOJO(&java8_time.MonthDay{Month: 6, Day: 16})
+	RegisterPOJO(&java8_time.Duration{Seconds: 30, Nanos: 10})
+	RegisterPOJO(&java8_time.Instant{Seconds: 100, Nanos: 10})
+	RegisterPOJO(&java8_time.ZoneOffSet{Seconds: 7200})
+	RegisterPOJO(&java8_time.OffsetDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 16}, Time: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}}, Offset: java8_time.ZoneOffSet{Seconds: 7200}})
+	RegisterPOJO(&java8_time.OffsetTime{LocalTime: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}, ZoneOffset: java8_time.ZoneOffSet{Seconds: 7200}})
+	RegisterPOJO(&java8_time.ZonedDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 16}, Time: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}}, Offset: java8_time.ZoneOffSet{Seconds: 7200}, ZoneId: "Z"})
 
 }
diff --git a/java8_time/duration.go b/java8_time/duration.go
index ee01d54..971a0ea 100644
--- a/java8_time/duration.go
+++ b/java8_time/duration.go
@@ -18,8 +18,8 @@
 package java8_time
 
 type Duration struct {
-	Second int64 `hessian:"second"`
-	Nano   int32 `hessian:"nano"`
+	Seconds int64 `hessian:"seconds"`
+	Nanos   int32 `hessian:"nanos"`
 }
 
 func (Duration) JavaClassName() string {


Test patch:
diff --git a/java8_time_test.go b/java8_time_test.go
index d9d5985..9529c95 100644
--- a/java8_time_test.go
+++ b/java8_time_test.go
@@ -24,18 +24,18 @@ import (
 
 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, Second: 6, Nano: 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_LocalDate", &java8_time.LocalDate{Year: 2020, Month: 6, Day: 16})
+	doTestTime(t, "java8_LocalTime", &java8_time.LocalTime{Hour: 6, Minute: 16})
+	doTestTime(t, "java8_LocalDateTime", &java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 16}, Time: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}})
+	doTestTime(t, "java8_MonthDay", &java8_time.MonthDay{Month: 6, Day: 16})
+	doTestTime(t, "java8_Duration", &java8_time.Duration{Seconds: 30, Nanos: 10})
+	doTestTime(t, "java8_Instant", &java8_time.Instant{Seconds: 100, Nanos: 10})
 	doTestTime(t, "java8_YearMonth", &java8_time.YearMonth{Year: 2020, Month: 6})
-	doTestTime(t, "java8_Period", &java8_time.Period{Years: 2020, Months: 6, Days: 6})
-	doTestTime(t, "java8_ZoneOffset", &java8_time.ZoneOffSet{Seconds: 0})
-	doTestTime(t, "java8_OffsetDateTime", &java8_time.OffsetDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 6}, Time: java8_time.LocalTime{Hour: 6, Minute: 6, Second: 6, Nano: 6}}, Offset: java8_time.ZoneOffSet{Seconds: -64800}})
-	doTestTime(t, "java8_OffsetTime", &java8_time.OffsetTime{LocalTime: java8_time.LocalTime{Hour: 6, Minute: 6, Second: 6, Nano: 6}, ZoneOffset: java8_time.ZoneOffSet{Seconds: -64800}})
-	doTestTime(t, "java8_ZonedDateTime", &java8_time.ZonedDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 6}, Time: java8_time.LocalTime{Hour: 6, Minute: 6, Second: 6, Nano: 6}}, Offset: java8_time.ZoneOffSet{Seconds: 0}, ZoneId: "Z"})
+	doTestTime(t, "java8_Period", &java8_time.Period{Years: 2020, Months: 6, Days: 16})
+	doTestTime(t, "java8_ZoneOffset", &java8_time.ZoneOffSet{Seconds: 7200})
+	doTestTime(t, "java8_OffsetDateTime", &java8_time.OffsetDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 16}, Time: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}}, Offset: java8_time.ZoneOffSet{Seconds: 7200}})
+	doTestTime(t, "java8_OffsetTime", &java8_time.OffsetTime{LocalTime: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}, ZoneOffset: java8_time.ZoneOffSet{Seconds: 7200}})
+	doTestTime(t, "java8_ZonedDateTime", &java8_time.ZonedDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 16}, Time: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}}, Offset: java8_time.ZoneOffSet{Seconds: 0}, ZoneId: "Z"})
 }
 
 func doTestTime(t *testing.T, method string, expected interface{}) {
diff --git a/test_hessian/src/main/java/test/TestJava8Time.java b/test_hessian/src/main/java/test/TestJava8Time.java
index 779fe5e..35dc521 100644
--- a/test_hessian/src/main/java/test/TestJava8Time.java
+++ b/test_hessian/src/main/java/test/TestJava8Time.java
@@ -22,39 +22,39 @@ import java.time.*;
 public class TestJava8Time {
 
     public static Duration java8_Duration() {
-        return Duration.ZERO;
+        return Duration.ofSeconds(30, 10);
     }
 
     public static Instant java8_Instant() {
-        return Instant.ofEpochMilli(100000L);
+        return Instant.ofEpochSecond(100, 10);
     }
 
     public static LocalDate java8_LocalDate() {
-        return LocalDate.of(2020, 6, 6);
+        return LocalDate.of(2020, 6, 16);
     }
 
     public static LocalDateTime java8_LocalDateTime() {
-        return LocalDateTime.of(2020, 6, 6, 6, 6, 6, 6);
+        return LocalDateTime.of(2020, 6, 16, 6, 5, 4, 3);
     }
 
     public static LocalTime java8_LocalTime() {
-        return LocalTime.of(6, 6);
+        return LocalTime.of(6, 16);
     }
 
     public static MonthDay java8_MonthDay() {
-        return MonthDay.of(6, 6);
+        return MonthDay.of(6, 16);
     }
 
     public static OffsetDateTime java8_OffsetDateTime() {
-        return OffsetDateTime.of(2020, 6, 6, 6, 6, 6, 6, ZoneOffset.MIN);
+        return OffsetDateTime.of(2020, 6, 16, 6, 5, 4, 3, java8_ZoneOffset());
     }
 
     public static OffsetTime java8_OffsetTime() {
-        return OffsetTime.of(6, 6, 6, 6, ZoneOffset.MIN);
+        return OffsetTime.of(6, 5, 4, 3, java8_ZoneOffset());
     }
 
     public static Period java8_Period() {
-        return Period.of(2020, 6, 6);
+        return Period.of(2020, 6, 16);
     }
 
     public static Year java8_Year() {
@@ -75,7 +75,7 @@ public class TestJava8Time {
     }
 
     public static ZoneOffset java8_ZoneOffset() {
-        return ZoneOffset.of("Z");
+        return ZoneOffset.ofHours(2);
     }
 
 }