Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/src/main/java/com/alibaba/fastjson2/JSONBDump.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,14 @@ private void dumpAny() {
jsonWriter.writeLocalDate(localDate);
break;
}
case BC_TIMESTAMP_WITH_TIMEZONE: {
int start = offset - 1;
try (JSONReader reader = JSONReader.ofJSONB(bytes, start, bytes.length - start, symbolTable)) {
jsonWriter.writeZonedDateTime(reader.readZonedDateTime());
offset = reader.getOffset();
}
break;
}
case BC_TIMESTAMP:
long epochSeconds = readInt64Value();
int nano = readInt32Value();
Expand Down
21 changes: 21 additions & 0 deletions core/src/test/java/com/alibaba/fastjson2/jsonb/JSONBDumTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -21,6 +24,24 @@

@Tag("jsonb")
public class JSONBDumTest {
@Test
public void testZonedDateTime() {
ZonedDateTime value = ZonedDateTime.of(2024, 1, 15, 12, 30, 45, 123456789, ZoneId.of("Europe/Paris"));
byte[] bytes = JSONB.toBytes(value);

assertEquals(JSON.toJSONString(value), JSONB.toJSONString(bytes));
assertEquals(JSON.toJSONString(value), JSONB.toJSONString(bytes, true));
}

@Test
public void testZonedDateTimeInArray() {
ZonedDateTime value = ZonedDateTime.of(2024, 1, 15, 12, 30, 45, 0, ZoneOffset.ofHours(5));
Object[] array = {value, 42};
byte[] bytes = JSONB.toBytes(array);

assertEquals(JSON.parseArray(JSON.toJSONString(array)), JSON.parseArray(JSONB.toJSONString(bytes)));
}

@Test
public void test_0() throws Exception {
Int1 vo = new Int1();
Expand Down