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


Java SimpleDateFormatSerializer类代码示例

本文整理汇总了Java中com.alibaba.fastjson.serializer.SimpleDateFormatSerializer的典型用法代码示例。如果您正苦于以下问题:Java SimpleDateFormatSerializer类的具体用法?Java SimpleDateFormatSerializer怎么用?Java SimpleDateFormatSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SimpleDateFormatSerializer类属于com.alibaba.fastjson.serializer包,在下文中一共展示了SimpleDateFormatSerializer类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testToJSONString2

import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer; //导入依赖的package包/类
@Test
public void testToJSONString2() throws Exception {
    SimpleJSON ss1 = SimpleJSON.getInstance()
            .addItem("Level", "\n")
            .addItem("MM", false)
            .addItem("Name", "SLf4j");
    
    final SimpleJSON ss2 = SimpleJSON.getInstance()
            .addItem("str1", ss1)
            .addItem("Name", "SLf4j")
            .addItem("LL", 125L)
            .addItem("now", new Date());

    //System.out.println(ss2.toString());
    
    final SimpleJSON ss3 = SimpleJSON.getInstance()
            .addItem("str1", ss1.getMap())
            .addItem("Name", "SLf4j")
            .addItem("LL", 125L)
            .addItem("now", new Date());
    final SerializeConfig mapping = new SerializeConfig();
    mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
    
    Assert.assertEquals(JSON.toJSONString(ss3.getMap(), mapping), 
            ss2.toString());
}
 
开发者ID:jretty-org,项目名称:jretty-util,代码行数:27,代码来源:JSONUtilsTest.java

示例2: test_codec

import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer; //导入依赖的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

示例3: test_codec_no_asm

import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer; //导入依赖的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

示例4: test_codec_asm

import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer; //导入依赖的package包/类
public void test_codec_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(true);
    
    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

示例5: test_codec_null_asm

import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer; //导入依赖的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

示例6: test_codec_null_no_asm

import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer; //导入依赖的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

示例7: test_0

import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer; //导入依赖的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

示例8: test_0

import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer; //导入依赖的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

示例9: test_for_loveflying

import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer; //导入依赖的package包/类
public void test_for_loveflying() throws Exception {
    User user = new User();
    user.setId(1l);
    user.setName("loveflying");
    user.setCreateTime(new java.sql.Timestamp(new Date().getTime()));

    UserLog userLog = new UserLog();
    userLog.setId(1l);
    userLog.setUser(user);
    user.getUserLogs().add(userLog);

    userLog = new UserLog();
    userLog.setId(2l);
    userLog.setUser(user);
    user.getUserLogs().add(userLog);

    SerializeConfig mapping = new SerializeConfig();

    mapping.put(java.sql.Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd"));
    mapping.put(java.sql.Timestamp.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
    // mapping.put(User.class, new JavaBeanSerializer(User.class,
    // Collections.singletonMap("id", "uid")));

    JSONObject jsonObject = (JSONObject) JSON.toJSON(user);
    jsonObject.put("ext", "新加的属性");
    System.out.println(jsonObject.toJSONString(jsonObject, mapping));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:28,代码来源:Bug_for_loveflying.java

示例10: createSuccessResponse

import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer; //导入依赖的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

示例11: setDateFormat

import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer; //导入依赖的package包/类
/**
 * 设置java.util.Date和java.sql.Date的格式(用于fastjson)
 * @param format
 */
public static void setDateFormat(String format)
{
	mapping.put(Date.class, new SimpleDateFormatSerializer(format));
	mapping.put(java.sql.Date.class, new SimpleDateFormatSerializer(format));
}
 
开发者ID:tywo45,项目名称:talent-aio,代码行数:10,代码来源:Json.java

示例12: setTimeFormat

import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer; //导入依赖的package包/类
/**
 * 设置java.sql.Time的格式(用于fastjson)
 * @param format
 */
public static void setTimeFormat(String format)
{
	mapping.put(java.sql.Time.class, new SimpleDateFormatSerializer(format));
}
 
开发者ID:tywo45,项目名称:talent-aio,代码行数:9,代码来源:Json.java

示例13: setTimestampFormat

import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer; //导入依赖的package包/类
/**
 * 设置java.sql.Timestamp的格式(用于fastjson)
 * @param format
 */
public static void setTimestampFormat(String format)
{
	mapping.put(java.sql.Timestamp.class, new SimpleDateFormatSerializer(format));
}
 
开发者ID:tywo45,项目名称:talent-aio,代码行数:9,代码来源:Json.java

示例14: JsonSeriaziler

import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer; //导入依赖的package包/类
public JsonSeriaziler(String dateFormat){
	features[features.length] = SerializerFeature.WriteDateUseDateFormat;
	mapping.put(java.util.Date.class, new SimpleDateFormatSerializer(dateFormat));
}
 
开发者ID:leopardoooo,项目名称:easyooo-framework,代码行数:5,代码来源:JsonSeriaziler.java


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