Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/test/java/com/alibaba/json/bvt/JSONObjectTest_readObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.alibaba.json.bvt; | ||
|
||
import com.alibaba.fastjson.JSONObject; | ||
import junit.framework.TestCase; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.ObjectInputStream; | ||
import java.io.ObjectOutputStream; | ||
|
||
public class JSONObjectTest_readObject extends TestCase { | ||
public void test_0() throws Exception { | ||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put("id", 123); | ||
|
||
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); | ||
ObjectOutputStream objOut = new ObjectOutputStream(bytesOut); | ||
objOut.writeObject(jsonObject); | ||
objOut.flush(); | ||
|
||
byte[] bytes = bytesOut.toByteArray(); | ||
|
||
ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytes); | ||
ObjectInputStream objIn = new ObjectInputStream(bytesIn); | ||
|
||
Object obj = objIn.readObject(); | ||
|
||
assertEquals(JSONObject.class, obj.getClass()); | ||
assertEquals(jsonObject, obj); | ||
} | ||
} |