support readMillis as int32, for issue #3471

This commit is contained in:
wenshao 2025-04-02 08:54:51 +08:00
parent 7abc631f99
commit f5c0b6287e
2 changed files with 49 additions and 0 deletions

View File

@ -3669,6 +3669,10 @@ final class JSONReaderJSONB
}
return decimal.intValue();
}
case BC_TIMESTAMP_MILLIS:
long millis = getLongBE(bytes, check7(offset, end));
offset += 8;
return (int) millis;
default:
if (type >= BC_STR_ASCII_FIX_MIN && type <= BC_STR_ASCII_FIX_MAX) {
int strlen = type - BC_STR_ASCII_FIX_MIN;

View File

@ -0,0 +1,45 @@
package com.alibaba.fastjson2.issues_3400;
import com.alibaba.fastjson2.JSONB;
import com.alibaba.fastjson2.JSONReader;
import com.alibaba.fastjson2.JSONWriter;
import org.junit.jupiter.api.Test;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Issue3471 {
@Test
public void test() throws Exception {
byte[] jsonBytes = JSONB.toBytes(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2025-04-01 12:47:10"),
JSONWriter.Feature.WriteClassName,
JSONWriter.Feature.FieldBased,
JSONWriter.Feature.ErrorOnNoneSerializable,
JSONWriter.Feature.ReferenceDetection,
JSONWriter.Feature.WriteNulls,
JSONWriter.Feature.NotWriteDefaultValue,
JSONWriter.Feature.NotWriteHashMapArrayListClassName,
JSONWriter.Feature.WriteNameAsSymbol);
JSONB.parseObject(jsonBytes, byte.class,
JSONReader.Feature.UseDefaultConstructorAsPossible,
JSONReader.Feature.ErrorOnNoneSerializable,
JSONReader.Feature.IgnoreAutoTypeNotMatch,
JSONReader.Feature.UseNativeObject,
JSONReader.Feature.FieldBased);
jsonBytes = JSONB.toBytes(new Date(),
JSONWriter.Feature.WriteClassName,
JSONWriter.Feature.FieldBased,
JSONWriter.Feature.ErrorOnNoneSerializable,
JSONWriter.Feature.ReferenceDetection,
JSONWriter.Feature.WriteNulls,
JSONWriter.Feature.NotWriteDefaultValue,
JSONWriter.Feature.NotWriteHashMapArrayListClassName,
JSONWriter.Feature.WriteNameAsSymbol);
JSONB.parseObject(jsonBytes, byte.class,
JSONReader.Feature.UseDefaultConstructorAsPossible,
JSONReader.Feature.ErrorOnNoneSerializable,
JSONReader.Feature.IgnoreAutoTypeNotMatch,
JSONReader.Feature.UseNativeObject,
JSONReader.Feature.FieldBased);
}
}