use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.
the class ListStringFieldTest_stream_TreeSet method test_null.
public void test_null() throws Exception {
String text = "{\"values\":null}";
JSONReader reader = new JSONReader(new StringReader(text));
Model model = reader.readObject(Model.class);
Assert.assertNull(model.values);
}
use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.
the class ListStringFieldTest_stream_array method test_map_empty_2.
public void test_map_empty_2() throws Exception {
String text = "{\"model\":[[]],\"model2\":[[]]}";
JSONReader reader = new JSONReader(new StringReader(text));
Map<String, Model> map = reader.readObject(new TypeReference<Map<String, Model>>() {
});
Model model = (Model) map.get("model");
Assert.assertEquals(0, model.values.size());
Model model2 = (Model) map.get("model2");
Assert.assertEquals(0, model2.values.size());
}
use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.
the class JSONReaderError method test_reader_error_1.
public void test_reader_error_1() throws Exception {
Exception error = null;
try {
JSONReader reader = new JSONReader(new StringReader("{\"id\":\"aa"));
reader.readObject(Model.class);
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.
the class JSONReaderError method test_reader_no_error_2.
public void test_reader_no_error_2() throws Exception {
JSONReader reader = new JSONReader(new StringReader("{\"model\":{\"id\":\"aa\",\"name\":\"wenshao\"},\"model2\":{\"id\":\"bb\",\"name\":\"ljw\"}}"));
Map<String, Model> map = reader.readObject(new TypeReference<Map<String, Model>>() {
});
{
Model model = map.get("model");
Assert.assertEquals("aa", model.id);
Assert.assertEquals("wenshao", model.name);
}
{
Model model = map.get("model2");
Assert.assertEquals("bb", model.id);
Assert.assertEquals("ljw", model.name);
}
reader.close();
}
use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.
the class JSONReaderError method test_reader_no_error.
public void test_reader_no_error() throws Exception {
JSONReader reader = new JSONReader(new StringReader("{\"id\":\"aa\",\"name\":\"wenshao\"}"));
Model model = reader.readObject(Model.class);
Assert.assertEquals("aa", model.id);
Assert.assertEquals("wenshao", model.name);
reader.close();
}
Aggregations