Improved JSON Node and Outputstream
This commit is contained in:
parent
7ccf26dc37
commit
86d463be88
5 changed files with 108 additions and 29 deletions
|
|
@ -61,7 +61,7 @@ public class JSONSerializerTest{
|
|||
data = data.replace("\"", "'");
|
||||
|
||||
assertEquals(
|
||||
"{'str': '1234', '@class': 'zutil.test.JSONSerializerTest$TestClass', 'obj1': {'@class': 'zutil.test.JSONSerializerTest$TestObj', 'value': '42', '@object_id': 2}, 'obj2': {'@class': 'zutil.test.JSONSerializerTest$TestObj', 'value': '42', '@object_id': 3}, 'decimal': '1.1', '@object_id': 1}",
|
||||
"{'str': 'abcd', '@class': 'zutil.test.JSONSerializerTest$TestClass', 'obj1': {'@class': 'zutil.test.JSONSerializerTest$TestObj', 'value': 42, '@object_id': 2}, 'obj2': {'@class': 'zutil.test.JSONSerializerTest$TestObj', 'value': 42, '@object_id': 3}, 'decimal': 1.1, '@object_id': 1}",
|
||||
data);
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ public class JSONSerializerTest{
|
|||
data = data.replace("\"", "'");
|
||||
|
||||
assertEquals(
|
||||
"{'@class': 'zutil.test.JSONSerializerTest$TestClassObjClone', 'obj1': {'@class': 'zutil.test.JSONSerializerTest$TestObj', 'value': '42', '@object_id': 2}, 'obj2': {'@class': 'zutil.test.JSONSerializerTest$TestObj', '@object_id': 2}, '@object_id': 1}",
|
||||
"{'@class': 'zutil.test.JSONSerializerTest$TestClassObjClone', 'obj1': {'@class': 'zutil.test.JSONSerializerTest$TestObj', 'value': 42, '@object_id': 2}, 'obj2': {'@object_id': 2}, '@object_id': 1}",
|
||||
data);
|
||||
}
|
||||
|
||||
|
|
@ -139,7 +139,7 @@ public class JSONSerializerTest{
|
|||
TestObj obj2;
|
||||
|
||||
public TestClass init(){
|
||||
this.str = "1234";
|
||||
this.str = "abcd";
|
||||
this.decimal = 1.1;
|
||||
this.obj1 = new TestObj().init();
|
||||
this.obj2 = new TestObj().init();
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import static org.junit.Assert.assertNull;
|
|||
import org.junit.Test;
|
||||
|
||||
import zutil.parser.DataNode;
|
||||
import zutil.parser.DataNode.DataType;
|
||||
import zutil.parser.json.JSONParser;
|
||||
|
||||
|
||||
|
|
@ -61,12 +62,45 @@ public class JSONTest{
|
|||
}
|
||||
|
||||
@Test
|
||||
public void number(){
|
||||
public void valueInt(){
|
||||
DataNode data = JSONParser.read("1234");
|
||||
assert(data.isValue());
|
||||
assertEquals( DataType.Number, data.getType());
|
||||
assertEquals( 1234, data.getInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueDouble(){
|
||||
DataNode data = JSONParser.read("12.34");
|
||||
assert(data.isValue());
|
||||
assertEquals( DataType.Number, data.getType());
|
||||
assertEquals( 12.34, data.getDouble(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueBoolean(){
|
||||
DataNode data = JSONParser.read("false");
|
||||
assert(data.isValue());
|
||||
assertEquals( DataType.Boolean, data.getType());
|
||||
assertEquals( false, data.getBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueBooleanUpperCase(){
|
||||
DataNode data = JSONParser.read("TRUE");
|
||||
assert(data.isValue());
|
||||
assertEquals( DataType.Boolean, data.getType());
|
||||
assertEquals( true, data.getBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueStringNoQuotes(){
|
||||
DataNode data = JSONParser.read("teststring");
|
||||
assert(data.isValue());
|
||||
assertEquals( DataType.String, data.getType());
|
||||
assertEquals( "teststring", data.getString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toManyCommasInList(){
|
||||
DataNode data = JSONParser.read("[1,2,3,]");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue