Reverted bad design choice to add newline in JSONWriter
This commit is contained in:
parent
34c9f5da91
commit
cba0b79203
2 changed files with 23 additions and 7 deletions
|
|
@ -143,7 +143,6 @@ public class JSONWriter{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flush(){
|
public void flush(){
|
||||||
out.print("\n");
|
|
||||||
out.flush();
|
out.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,7 @@ import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import zutil.io.StringOutputStream;
|
import zutil.io.StringOutputStream;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.*;
|
||||||
import java.io.Serializable;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
@ -92,7 +90,7 @@ public class JSONSerializerTest{
|
||||||
data = data.replace("\"", "'");
|
data = data.replace("\"", "'");
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"{'@class': 'zutil.parser.json.JSONSerializerTest$TestClassArray', 'array': [1, 2, 3, 4], '@object_id': 1}\n",
|
"{'@class': 'zutil.parser.json.JSONSerializerTest$TestClassArray', 'array': [1, 2, 3, 4], '@object_id': 1}",
|
||||||
data);
|
data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,7 +117,7 @@ public class JSONSerializerTest{
|
||||||
String data = writeObjectToJson(sourceObj, false);
|
String data = writeObjectToJson(sourceObj, false);
|
||||||
data = data.replace("\"", "'");
|
data = data.replace("\"", "'");
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"{'decimal': 0.0}\n",
|
"{'decimal': 0.0}",
|
||||||
data);
|
data);
|
||||||
|
|
||||||
TestClass targetObj = sendReceiveObject(sourceObj);
|
TestClass targetObj = sendReceiveObject(sourceObj);
|
||||||
|
|
@ -156,6 +154,25 @@ public class JSONSerializerTest{
|
||||||
TestClassList.assertEquals(sourceObj, targetObj);
|
TestClassList.assertEquals(sourceObj, targetObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSerializerWithMultipleObj() throws InterruptedException, IOException, ClassNotFoundException{
|
||||||
|
TestClass sourceObj1 = new TestClass().init();
|
||||||
|
TestClass sourceObj2 = new TestClass().init();
|
||||||
|
|
||||||
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
|
JSONObjectOutputStream out = new JSONObjectOutputStream(buffer);
|
||||||
|
out.enableMetaData(false);
|
||||||
|
out.writeObject(sourceObj1);
|
||||||
|
out.writeObject(sourceObj2);
|
||||||
|
out.flush();
|
||||||
|
|
||||||
|
JSONObjectInputStream in = new JSONObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
|
||||||
|
TestClass targetObj1 = in.readObject(TestClass.class);
|
||||||
|
TestClass.assertEquals(sourceObj1, targetObj1);
|
||||||
|
TestClass targetObj2 = in.readObject(TestClass.class);
|
||||||
|
TestClass.assertEquals(sourceObj2, targetObj2);
|
||||||
|
}
|
||||||
|
|
||||||
/******************* Utility Functions ************************************/
|
/******************* Utility Functions ************************************/
|
||||||
|
|
||||||
public static <T> T sendReceiveObject(T sourceObj) throws IOException{
|
public static <T> T sendReceiveObject(T sourceObj) throws IOException{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue