use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class DateFormatSerializerTest method test_date_4.
public void test_date_4() throws Exception {
SerializeWriter out = new SerializeWriter();
SerializeConfig config = new SerializeConfig();
JSONSerializer serializer = new JSONSerializer(out, config);
SimpleDateFormat format = new SimpleDateFormat("yyyy");
format.setTimeZone(JSON.defaultTimeZone);
serializer.write(new VO(format));
Assert.assertEquals("{\"format\":\"yyyy\"}", out.toString());
JSON.parseObject(out.toString(), VO.class);
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class DateFormatSerializerTest method test_date_2.
public void test_date_2() throws Exception {
SerializeWriter out = new SerializeWriter();
SerializeConfig config = new SerializeConfig();
JSONSerializer serializer = new JSONSerializer(out, config);
serializer.config(SerializerFeature.WriteMapNullValue, true);
serializer.write(new VO());
Assert.assertEquals("{\"format\":null}", out.toString());
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class ErrorTest method test_error.
public void test_error() throws Exception {
SerializeConfig config = new SerializeConfig();
config.put(A.class, new ObjectSerializer() {
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
throw new IOException();
}
});
JSONSerializer ser = new JSONSerializer(config);
{
Exception error = null;
try {
ser.write(new A());
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
{
Exception error = null;
try {
B b = new B();
b.setId(new A());
ser.write(b);
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class JSONSerializerTest method test_8.
public void test_8() throws Exception {
JSONSerializer serializer = new JSONSerializer();
serializer.write(new B());
Assert.assertEquals("{}", serializer.getWriter().toString());
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class JSONSerializerTest method test_9.
public void test_9() throws Exception {
JSONSerializer serializer = new JSONSerializer();
serializer.write(new D(3L));
Assert.assertEquals("{\"id\":3}", serializer.getWriter().toString());
}
Aggregations