Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class JSONArray
static ObjectReader<JSONArray> arrayReader;
static ObjectReader<JSONObject> objectReader;

private static final long serialVersionUID = 1L;

private List list = new com.alibaba.fastjson2.JSONArray();

protected transient Object relatedArray;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.alibaba.fastjson;

import org.junit.jupiter.api.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class JSONArrayTest_readObject {
@Test
public void test_serialVersionUID() {
ObjectStreamClass desc = ObjectStreamClass.lookup(JSONArray.class);
assertEquals(1L, desc.getSerialVersionUID());
}

@Test
public void test_0() throws Exception {
JSONArray jsonArray = new JSONArray();
jsonArray.add(123);
jsonArray.add("hello");
jsonArray.add(new JSONObject());

ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
ObjectOutputStream objOut = new ObjectOutputStream(bytesOut);
objOut.writeObject(jsonArray);
objOut.flush();

byte[] bytes = bytesOut.toByteArray();

ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytes);
ObjectInputStream objIn = new ObjectInputStream(bytesIn);

Object obj = objIn.readObject();

assertEquals(JSONArray.class, obj.getClass());
assertEquals(jsonArray, obj);
}

@Test
public void test_1() throws Exception {
JSONArray jsonArray = JSON.parseArray("[1,2,3,{\"id\":123}]");

ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
ObjectOutputStream objOut = new ObjectOutputStream(bytesOut);
objOut.writeObject(jsonArray);
objOut.flush();

byte[] bytes = bytesOut.toByteArray();

ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytes);
ObjectInputStream objIn = new ObjectInputStream(bytesIn);

Object obj = objIn.readObject();

assertEquals(JSONArray.class, obj.getClass());
assertEquals(jsonArray, obj);
}
}
Loading