use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class JSON_toJSONStringTest method test_1.
public void test_1() throws Exception {
User user = new User();
user.setId(123);
user.setName("毛头");
SerializeConfig mapping = new SerializeConfig();
mapping.put(User.class, new JavaBeanSerializer(User.class, Collections.singletonMap("id", "uid")));
JSONSerializer serializer = new JSONSerializer(mapping);
serializer.write(user);
String jsonString = serializer.toString();
Assert.assertEquals("{\"uid\":123}", jsonString);
}
use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class ListFieldTest method test_codec_null.
public void test_codec_null() throws Exception {
V0 v = new V0();
SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(false);
String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
Assert.assertEquals("{\"value\":null}", text);
ParserConfig config = new ParserConfig();
config.setAutoTypeSupport(true);
config.setAsmEnable(false);
V0 v1 = JSON.parseObject(text, V0.class, config, JSON.DEFAULT_PARSER_FEATURE);
Assert.assertEquals(v1.getValue(), v.getValue());
}
use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class LocaleFieldTest method test_codec.
public void test_codec() throws Exception {
User user = new User();
user.setValue(Locale.CANADA);
SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(false);
String text = JSON.toJSONString(user, mapping, SerializerFeature.WriteMapNullValue);
User user1 = JSON.parseObject(text, User.class);
Assert.assertEquals(user1.getValue(), user.getValue());
}
use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class LocaleFieldTest method test_codec_null.
public void test_codec_null() throws Exception {
User user = new User();
user.setValue(null);
SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(false);
String text = JSON.toJSONString(user, mapping, SerializerFeature.WriteMapNullValue);
User user1 = JSON.parseObject(text, User.class);
Assert.assertEquals(user1.getValue(), user.getValue());
}
use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class LongArrayFieldTest method test_codec_null.
public void test_codec_null() throws Exception {
V0 v = new V0();
SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(false);
String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
Assert.assertEquals("{\"value\":null}", text);
V0 v1 = JSON.parseObject(text, V0.class);
Assert.assertEquals(v1.getValue(), v.getValue());
}
Aggregations