本文整理汇总了Java中com.alibaba.fastjson.serializer.SerializeConfig.put方法的典型用法代码示例。如果您正苦于以下问题:Java SerializeConfig.put方法的具体用法?Java SerializeConfig.put怎么用?Java SerializeConfig.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.serializer.SerializeConfig
的用法示例。
在下文中一共展示了SerializeConfig.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_bean_2
import com.alibaba.fastjson.serializer.SerializeConfig; //导入方法依赖的package包/类
public void test_bean_2() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", 123);
PO vo = TypeUtils.castToJavaBean(map, PO.class);
Assert.assertEquals(123, vo.id);
SerializeWriter out = new SerializeWriter();
try {
SerializeConfig config = new SerializeConfig();
JSONSerializer serializer = new JSONSerializer(out, config);
config.put(PO.class, new JavaBeanSerializer(PO.class, Collections.singletonMap("id", "ID")));
serializer.write(vo);
Assert.assertEquals("{\"ID\":123}", out.toString());
} finally {
out.close();
}
}
示例2: test_bean_3
import com.alibaba.fastjson.serializer.SerializeConfig; //导入方法依赖的package包/类
public void test_bean_3() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", 123);
PO vo = TypeUtils.castToJavaBean(map, PO.class);
Assert.assertEquals(123, vo.id);
SerializeWriter out = new SerializeWriter();
try {
SerializeConfig config = new SerializeConfig();
JSONSerializer serializer = new JSONSerializer(out, config);
config.put(PO.class, new JavaBeanSerializer(PO.class, Collections.singletonMap("id", (String) null)));
serializer.write(vo);
Assert.assertEquals("{}", out.toString());
} finally {
out.close();
}
}
示例3: test_0
import com.alibaba.fastjson.serializer.SerializeConfig; //导入方法依赖的package包/类
public void test_0() throws Exception {
SerializeConfig config = new SerializeConfig();
config.put(Currency.class
, config.createJavaBeanSerializer(Currency.class));
JSONObject jsonObject = new JSONObject();
jsonObject.put("value", Currency.getInstance("CNY"));
String text = JSON.toJSONString(jsonObject, config);
System.out.println(text);
String str1 = "{\"value\":{\"currencyCode\":\"CNY\",\"displayName\":\"Chinese Yuan\",\"symbol\":\"CNY\"}}";
String str2 = "{\"value\":{\"currencyCode\":\"CNY\",\"displayName\":\"人民币\",\"symbol\":\"¥\"}}";
String str3 = "{\"value\":{\"currencyCode\":\"CNY\",\"displayName\":\"Chinese Yuan\",\"numericCodeAsString\":\"156\",\"symbol\":\"CN¥\"}}";
assertTrue(text.equals(str1)
|| text.equals(str2)
|| text.equals(str3));
Currency currency = JSON.parseObject(text, VO.class).value;
assertSame(Currency.getInstance("CNY"), currency);
}
示例4: main
import com.alibaba.fastjson.serializer.SerializeConfig; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
SerializeConfig config = SerializeConfig.getGlobalInstance();
config.put(MediaContent.class, new MediaContentSerializer());
config.put(Media.class, new MediaSerializer());
config.put(Image.class, new ImageSerializer());
System.out.println(System.getProperty("java.vm.name") + " " + System.getProperty("java.runtime.version"));
List<String> arguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
System.out.println(arguments);
MediaContent content = EishayDecodeBytes.instance.getContent();
String text = encode(content);
System.out.println(text);
for (int i = 0; i < 10; ++i) {
perf(text);
}
}
示例5: test_0
import com.alibaba.fastjson.serializer.SerializeConfig; //导入方法依赖的package包/类
public void test_0() throws Exception {
User user = new User();
user.setId(123);
user.setName("毛头");
SerializeConfig mapping = new SerializeConfig();
mapping.put(User.class, new JavaBeanSerializer(User.class, "id"));
JSONSerializer serializer = new JSONSerializer(mapping);
serializer.write(user);
String jsonString = serializer.toString();
Assert.assertEquals("{\"id\":123}", jsonString);
}
示例6: test_1
import com.alibaba.fastjson.serializer.SerializeConfig; //导入方法依赖的package包/类
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);
}
示例7: test_codec
import com.alibaba.fastjson.serializer.SerializeConfig; //导入方法依赖的package包/类
public void test_codec() throws Exception {
SerializeConfig mapping = new SerializeConfig();
mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd"));
V0 v = new V0();
v.setValue(new Date());
String text = JSON.toJSONString(v, mapping);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", JSON.defaultLocale);
format.setTimeZone(JSON.defaultTimeZone);
Assert.assertEquals("{\"value\":" + JSON.toJSONString(format.format(v.getValue())) + "}", text);
}
示例8: test_codec_no_asm
import com.alibaba.fastjson.serializer.SerializeConfig; //导入方法依赖的package包/类
public void test_codec_no_asm() throws Exception {
V0 v = new V0();
v.setValue(new Date());
SerializeConfig mapping = new SerializeConfig();
mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd"));
mapping.setAsmEnable(false);
String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", JSON.defaultLocale);
format.setTimeZone(JSON.defaultTimeZone);
Assert.assertEquals("{\"value\":" + JSON.toJSONString(format.format(v.getValue())) + "}", text);
}
示例9: createSuccessResponse
import com.alibaba.fastjson.serializer.SerializeConfig; //导入方法依赖的package包/类
public static String createSuccessResponse(Integer httpCode, String message, Object result, SerializerFeature serializerFeature, SerializeFilter filter, HttpServletResponse response){
PrintWriter printWriter = null;
String jsonString = "";
try {
response.setCharacterEncoding(RESPONSE_CHARACTERENCODING);
response.setContentType(RESPONSE_CONTENTTYPE);
response.setStatus(httpCode);
printWriter = response.getWriter();
SerializeConfig config = new SerializeConfig();
config.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd"));
Map<String, Object> map = new HashMap<String, Object>();
if(null != result){
map.put("res_code", httpCode);
map.put("message", message);
map.put("data",result);
if(null!=filter){
jsonString = JSONObject.toJSONString(map,filter,serializerFeature);
}else{
// jsonString = JSONObject.toJSONString(map,config,serializerFeature);
jsonString = JSONObject.toJSONStringWithDateFormat(map,"yyyy-MM-dd");
}
printWriter.write(jsonString);
}
printWriter.flush();
} catch (Exception e) {
log.error("createResponse failed", e);
} finally {
if(null!=printWriter)printWriter.close();
}
return jsonString;
}
示例10: test_codec_null_asm
import com.alibaba.fastjson.serializer.SerializeConfig; //导入方法依赖的package包/类
public void test_codec_null_asm() throws Exception {
V0 v = new V0();
SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(true);
String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd"));
Assert.assertEquals("{\"value\":null}", text);
V0 v1 = JSON.parseObject(text, V0.class);
Assert.assertEquals(v1.getValue(), v.getValue());
}
示例11: test_codec_null_no_asm
import com.alibaba.fastjson.serializer.SerializeConfig; //导入方法依赖的package包/类
public void test_codec_null_no_asm() throws Exception {
V0 v = new V0();
SerializeConfig mapping = new SerializeConfig();
mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd"));
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());
}
示例12: test_0
import com.alibaba.fastjson.serializer.SerializeConfig; //导入方法依赖的package包/类
public void test_0() throws Exception {
SerializeConfig config = new SerializeConfig();
config.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd"));
config.setAsmEnable(false);
Entity object = new Entity();
object.setValue(new Date());
String text = JSON.toJSONString(object, config);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", JSON.defaultLocale);
format.setTimeZone(JSON.defaultTimeZone);
Assert.assertEquals("{\"value\":\"" + format.format(object.getValue()) + "\"}", text);
}
示例13: test_0
import com.alibaba.fastjson.serializer.SerializeConfig; //导入方法依赖的package包/类
public void test_0() throws Exception {
SerializeConfig mapping = new SerializeConfig();
mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd"));
Entity object = new Entity();
object.setValue(new Date());
String text = JSON.toJSONString(object, mapping);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", JSON.defaultLocale);
format.setTimeZone(JSON.defaultTimeZone);
Assert.assertEquals("{\"value\":\"" + format.format(object.getValue()) + "\"}", text);
}
示例14: test_serialize
import com.alibaba.fastjson.serializer.SerializeConfig; //导入方法依赖的package包/类
public void test_serialize() throws Exception {
SerializeConfig config = new SerializeConfig();
config.put(ResultCode.class, new ResultCodeSerilaizer());
Result result = new Result();
result.code = ResultCode.SIGN_ERROR;
String json = JSON.toJSONString(result, config);
Assert.assertEquals("{\"code\":17}", json);
}
示例15: test_0
import com.alibaba.fastjson.serializer.SerializeConfig; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
public void test_0() throws Exception {
Map values = new HashMap();
Double v = 9.00;
values.put("double", v);
SerializeConfig config = new SerializeConfig();
config.put(Double.class, new DoubleSerializer(new DecimalFormat("###.00")));
Assert.assertEquals("{\"double\":9.00}", JSON.toJSONString(values, config));
}