Skip to content

Commit d4425f6

Browse files
committed
Optimized testReadByte of FastJson2SerializationTest
1 parent 6a69ad4 commit d4425f6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

dubbo-serialization/dubbo-serialization-fastjson2/src/test/java/org/apache/dubbo/common/serialize/fastjson2/FastJson2SerializationTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import java.io.ByteArrayInputStream;
2828
import java.io.ByteArrayOutputStream;
2929
import java.io.IOException;
30+
import java.text.ParseException;
31+
import java.text.SimpleDateFormat;
3032
import java.util.Date;
3133
import java.util.HashMap;
3234
import java.util.LinkedList;
@@ -204,7 +206,7 @@ void testReadEvent() throws IOException, ClassNotFoundException {
204206
}
205207

206208
@Test
207-
void testReadByte() throws IOException {
209+
void testReadByte() throws IOException, ParseException {
208210
FrameworkModel frameworkModel = new FrameworkModel();
209211
Serialization serialization =
210212
frameworkModel.getExtensionLoader(Serialization.class).getExtension("fastjson2");
@@ -227,7 +229,9 @@ void testReadByte() throws IOException {
227229
{
228230
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
229231
ObjectOutput objectOutput = serialization.serialize(url, outputStream);
230-
objectOutput.writeObject(new Date());
232+
// the milliseconds of date should not be zero, otherwise the output could be read as byte.
233+
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse("2025-04-01 12:47:10.001");
234+
objectOutput.writeObject(date);
231235
objectOutput.flushBuffer();
232236

233237
byte[] bytes = outputStream.toByteArray();

0 commit comments

Comments
 (0)