-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix JSONArray.getString with Date type, for issue #2596
- Loading branch information
Showing
2 changed files
with
64 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
48 changes: 48 additions & 0 deletions
48
fastjson1-compatible/src/test/java/com/alibaba/fastjson2/issue_2300/Issue2596.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,48 @@ | ||
package com.alibaba.fastjson2.issue_2300; | ||
|
||
import com.alibaba.fastjson2.JSONArray; | ||
import com.alibaba.fastjson2.JSONObject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.*; | ||
import java.time.chrono.HijrahDate; | ||
import java.time.chrono.JapaneseDate; | ||
import java.time.chrono.MinguoDate; | ||
import java.time.chrono.ThaiBuddhistDate; | ||
import java.time.temporal.TemporalAccessor; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue2596 { | ||
@Test | ||
public void test() { | ||
testTemporal(LocalDate.now(), LocalDateTime.now(), | ||
LocalTime.now(), ZonedDateTime.now(), | ||
OffsetDateTime.now(), Instant.now(), | ||
HijrahDate.now(), JapaneseDate.now(), | ||
OffsetTime.now(), MinguoDate.now(), | ||
ThaiBuddhistDate.now(), YearMonth.now(), | ||
MonthDay.now(), DayOfWeek.of(3)); | ||
} | ||
|
||
void testTemporal(TemporalAccessor... targets) { | ||
com.alibaba.fastjson.JSONObject j1 = new com.alibaba.fastjson.JSONObject(); | ||
JSONObject j2 = new JSONObject(); | ||
|
||
com.alibaba.fastjson.JSONArray array1 = new com.alibaba.fastjson.JSONArray(); | ||
JSONArray array2 = new JSONArray(); | ||
|
||
int i = 0; | ||
for (TemporalAccessor target : targets) { | ||
j1.put("data", target); | ||
j2.put("data", target); | ||
assertEquals(j1.getString("data"), j2.getString("data")); | ||
|
||
array1.add(target); | ||
array2.add(target); | ||
assertEquals(array1.getString(i), array2.getString(i)); | ||
|
||
i++; | ||
} | ||
} | ||
} |