|
| 1 | +package com.alibaba.fastjson2.issues_3400; |
| 2 | + |
| 3 | +import com.alibaba.fastjson2.JSONB; |
| 4 | +import com.alibaba.fastjson2.JSONReader; |
| 5 | +import com.alibaba.fastjson2.JSONWriter; |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | + |
| 8 | +import java.text.SimpleDateFormat; |
| 9 | +import java.util.Date; |
| 10 | + |
| 11 | +public class Issue3471 { |
| 12 | + @Test |
| 13 | + public void test() throws Exception { |
| 14 | + byte[] jsonBytes = JSONB.toBytes(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2025-04-01 12:47:10"), |
| 15 | + JSONWriter.Feature.WriteClassName, |
| 16 | + JSONWriter.Feature.FieldBased, |
| 17 | + JSONWriter.Feature.ErrorOnNoneSerializable, |
| 18 | + JSONWriter.Feature.ReferenceDetection, |
| 19 | + JSONWriter.Feature.WriteNulls, |
| 20 | + JSONWriter.Feature.NotWriteDefaultValue, |
| 21 | + JSONWriter.Feature.NotWriteHashMapArrayListClassName, |
| 22 | + JSONWriter.Feature.WriteNameAsSymbol); |
| 23 | + JSONB.parseObject(jsonBytes, byte.class, |
| 24 | + JSONReader.Feature.UseDefaultConstructorAsPossible, |
| 25 | + JSONReader.Feature.ErrorOnNoneSerializable, |
| 26 | + JSONReader.Feature.IgnoreAutoTypeNotMatch, |
| 27 | + JSONReader.Feature.UseNativeObject, |
| 28 | + JSONReader.Feature.FieldBased); |
| 29 | + jsonBytes = JSONB.toBytes(new Date(), |
| 30 | + JSONWriter.Feature.WriteClassName, |
| 31 | + JSONWriter.Feature.FieldBased, |
| 32 | + JSONWriter.Feature.ErrorOnNoneSerializable, |
| 33 | + JSONWriter.Feature.ReferenceDetection, |
| 34 | + JSONWriter.Feature.WriteNulls, |
| 35 | + JSONWriter.Feature.NotWriteDefaultValue, |
| 36 | + JSONWriter.Feature.NotWriteHashMapArrayListClassName, |
| 37 | + JSONWriter.Feature.WriteNameAsSymbol); |
| 38 | + JSONB.parseObject(jsonBytes, byte.class, |
| 39 | + JSONReader.Feature.UseDefaultConstructorAsPossible, |
| 40 | + JSONReader.Feature.ErrorOnNoneSerializable, |
| 41 | + JSONReader.Feature.IgnoreAutoTypeNotMatch, |
| 42 | + JSONReader.Feature.UseNativeObject, |
| 43 | + JSONReader.Feature.FieldBased); |
| 44 | + } |
| 45 | +} |
0 commit comments