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