use of com.alibaba.fastjson.serializer.SerializeConfig 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.SerializeConfig in project fastjson by alibaba.
the class ByteArrayTest method test_bytes.
public void test_bytes() throws Exception {
VO vo = new VO();
SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(false);
SerializerFeature[] features = { SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty };
String text1 = JSON.toJSONString(vo, mapping, features);
Assert.assertEquals("{\"value\":[]}", text1);
String text2 = JSON.toJSONString(vo, features);
Assert.assertEquals("{\"value\":[]}", text2);
}
use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class JSONSerializerDeprecatedTest method test_.
public void test_() throws Exception {
JSONSerializer ser = new JSONSerializer(new SerializeConfig());
ser.setDateFormat(new ISO8601DateFormat());
Assert.assertEquals(null, ser.getDateFormatPattern());
ser.close();
}
use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class JSONSerializerMapTest method test_0.
public void test_0() throws Exception {
SerializeConfig map = new SerializeConfig();
Assert.assertFalse(0 == size(map));
Assert.assertEquals(true, map.get(Integer.class) == IntegerCodec.instance);
Assert.assertEquals(true, map.put(Integer.class, IntegerCodec.instance));
Assert.assertEquals(true, map.put(Integer.class, IntegerCodec.instance));
Assert.assertEquals(true, map.put(Integer.class, IntegerCodec.instance));
Assert.assertEquals(true, map.get(Integer.class) == IntegerCodec.instance);
Assert.assertFalse(0 == size(map));
}
use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class SerializeConfigTest method test_1.
public void test_1() throws Exception {
SerializeConfig config = new SerializeConfig();
config.setTypeKey("%type");
Assert.assertEquals("%type", config.getTypeKey());
Assert.assertEquals("{\"%type\":\"java.util.LinkedHashMap\"}", JSON.toJSONString(new LinkedHashMap(), config, SerializerFeature.WriteClassName));
}
Aggregations