use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.
the class Issue143 method test_for_issue.
public void test_for_issue() throws Exception {
String text = "{\"rec\":[{},{}]}";
JsonStroe store = new JsonStroe();
JSONReader reader = new JSONReader(new StringReader(text));
reader.startObject();
String key = reader.readString();
Assert.assertEquals("rec", key);
reader.startArray();
List<KeyValue> list = new ArrayList<KeyValue>();
while (reader.hasNext()) {
KeyValue keyValue = reader.readObject(KeyValue.class);
list.add(keyValue);
}
store.setRec(list);
reader.endArray();
reader.endObject();
reader.close();
}
use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.
the class Issue169 method test_for_issue.
public void test_for_issue() throws Exception {
StringWriter strWriter = new StringWriter();
SectionRequest req = new SectionRequest();
// 父类中的属性
req.setScreenHeight(100);
// 父类中的属性
req.setScreenWidth(12);
req.setTag("11");
JSONWriter writer = new JSONWriter(strWriter);
writer.startArray();
writer.writeObject(req);
writer.endArray();
writer.close();
String text = strWriter.toString();
StringReader strReader = new StringReader(text);
JSONReader reader = new JSONReader(strReader);
reader.startArray();
;
while (reader.hasNext()) {
SectionRequest vo = reader.readObject(SectionRequest.class);
System.out.println("tag:" + vo.getTag() + "screenHeight:" + vo.getScreenHeight() + "ScreenWidth:" + vo.getScreenWidth());
Assert.assertEquals(100, vo.getScreenHeight());
Assert.assertEquals(12, vo.getScreenWidth());
Assert.assertEquals("11", vo.getTag());
}
reader.endArray();
reader.close();
}
use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.
the class Bug_for_issue_448 method test_for_issue.
// skip
public void test_for_issue() throws Exception {
final int value_size = 1024 * 16;
List<Model> list = new ArrayList<Model>();
for (int i = 0; i < 10; ++i) {
Model model = new Model();
char[] buf = new char[value_size];
for (int j = 0; j < buf.length; ++j) {
buf[j] = (char) ('a' + j);
}
model.value = new String(buf);
list.add(model);
}
String text = JSON.toJSONString(list);
JSONReader reader = new JSONReader(new StringReader(text));
reader.startArray();
while (reader.hasNext()) {
Model model = reader.readObject(Model.class);
String value = model.value;
Assert.assertEquals(value_size, value.length());
for (int i = 0; i < value.length(); ++i) {
char ch = value.charAt(i);
Assert.assertEquals("error : index_" + i, (char) ('a' + i), ch);
}
}
reader.endArray();
reader.close();
}
use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.
the class DateTest_tz method test_codec.
// protected void setUp() throws Exception {
// JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
// JSON.defaultLocale = Locale.CHINA;
// }
public void test_codec() throws Exception {
JSONReader reader = new JSONReader(new StringReader("{\"value\":\"2016-04-29\"}"));
reader.setLocale(Locale.CHINA);
reader.setTimzeZone(TimeZone.getTimeZone("Asia/Shanghai"));
Model model = reader.readObject(Model.class);
Assert.assertNotNull(model.value);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
format.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
Date date = format.parse("2016-04-29");
Assert.assertEquals(date.getTime(), model.value.getTime());
Assert.assertEquals(TimeZone.getTimeZone("Asia/Shanghai"), reader.getTimzeZone());
Assert.assertEquals(Locale.CHINA, reader.getLocal());
reader.close();
}
use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.
the class Issue72 method test_for_issue.
public void test_for_issue() throws Exception {
InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue72.json");
JSONReader reader = null;
try {
byte[] rowBatchBytes = null;
byte[] fileBatchBytes = null;
reader = new JSONReader(new InputStreamReader(is));
reader.startArray();
while (reader.hasNext()) {
if (rowBatchBytes == null) {
rowBatchBytes = reader.readObject(byte[].class);
} else if (fileBatchBytes == null) {
fileBatchBytes = reader.readObject(byte[].class);
} else {
throw new Exception("archive data json parse failed!");
}
}
reader.endArray();
} finally {
IOUtils.close(reader);
}
}
Aggregations