-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deserialize support ZoneOffset, for issue #1789
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
core/src/test/java/com/alibaba/fastjson2/issues_1700/Issue1789.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.alibaba.fastjson2.issues_1700; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import lombok.Data; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.*; | ||
import java.util.Date; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class Issue1789 { | ||
@Test | ||
public void test() { | ||
Person person = new Person(); | ||
person.setZoneOffset(ZoneOffset.ofHours(8)); | ||
String str = JSON.toJSONString(person); // {"zoneOffset":"+08:00"} | ||
Person person1 = JSON.parseObject(str, Person.class); | ||
assertNotNull(person1); | ||
assertEquals(person.zoneOffset, person1.zoneOffset); | ||
} | ||
|
||
@Data | ||
public static class Person { | ||
private String name; | ||
private Integer age; | ||
private Object object; | ||
private Date date; | ||
private Duration duration; | ||
private LocalTime localTime; | ||
private LocalDate localDate; | ||
private LocalDateTime localDateTime; | ||
private ZoneOffset zoneOffset = ZoneOffset.ofHours(8); | ||
} | ||
} |