当前位置: 首页>>代码示例>>Java>>正文


Java SerializeConfig.put方法代码示例

本文整理汇总了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();
    }

    
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:TypeUtilsTest_castToJavaBean.java

示例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();
    }

    
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:TypeUtilsTest_castToJavaBean.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:CurrencyTest5.java

示例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);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:BenchmarkMain_EishayEncode_WriteAsArray.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:JSON_toJSONStringTest.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:JSON_toJSONStringTest.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:DateFieldTest3.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:DateFieldTest3.java

示例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;
	}
 
开发者ID:leon66666,项目名称:spring-boot-frameset,代码行数:35,代码来源:ServletUtil.java

示例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());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:DateFieldTest3.java

示例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());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:DateFieldTest3.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:DateFieldTest7.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:DateFieldTest6.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:ObjectSerializerTest.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:DoubleTest_custom2.java


注:本文中的com.alibaba.fastjson.serializer.SerializeConfig.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。