@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());
}
java类com.alibaba.fastjson.serializer.SimpleDateFormatSerializer的实例源码
JSONUtilsTest.java 文件源码
项目:jretty-util
阅读 43
收藏 0
点赞 0
评论 0
DateFieldTest3.java 文件源码
项目:GitHub
阅读 34
收藏 0
点赞 0
评论 0
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);
}
DateFieldTest3.java 文件源码
项目:GitHub
阅读 26
收藏 0
点赞 0
评论 0
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);
}
DateFieldTest3.java 文件源码
项目:GitHub
阅读 39
收藏 0
点赞 0
评论 0
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);
}
DateFieldTest3.java 文件源码
项目:GitHub
阅读 34
收藏 0
点赞 0
评论 0
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());
}
DateFieldTest3.java 文件源码
项目:GitHub
阅读 29
收藏 0
点赞 0
评论 0
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());
}
DateFieldTest7.java 文件源码
项目:GitHub
阅读 32
收藏 0
点赞 0
评论 0
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);
}
DateFieldTest6.java 文件源码
项目:GitHub
阅读 28
收藏 0
点赞 0
评论 0
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);
}
Bug_for_loveflying.java 文件源码
项目:GitHub
阅读 39
收藏 0
点赞 0
评论 0
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));
}
ServletUtil.java 文件源码
项目:spring-boot-frameset
阅读 39
收藏 0
点赞 0
评论 0
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;
}
ServletUtil.java 文件源码
项目:spring-boot-frameset
阅读 29
收藏 0
点赞 0
评论 0
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;
}
Json.java 文件源码
项目:talent-aio
阅读 41
收藏 0
点赞 0
评论 0
/**
* 设置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));
}
Json.java 文件源码
项目:talent-aio
阅读 55
收藏 0
点赞 0
评论 0
/**
* 设置java.sql.Time的格式(用于fastjson)
* @param format
*/
public static void setTimeFormat(String format)
{
mapping.put(java.sql.Time.class, new SimpleDateFormatSerializer(format));
}
Json.java 文件源码
项目:talent-aio
阅读 35
收藏 0
点赞 0
评论 0
/**
* 设置java.sql.Timestamp的格式(用于fastjson)
* @param format
*/
public static void setTimestampFormat(String format)
{
mapping.put(java.sql.Timestamp.class, new SimpleDateFormatSerializer(format));
}
JsonSeriaziler.java 文件源码
项目:easyooo-framework
阅读 34
收藏 0
点赞 0
评论 0
public JsonSeriaziler(String dateFormat){
features[features.length] = SerializerFeature.WriteDateUseDateFormat;
mapping.put(java.util.Date.class, new SimpleDateFormatSerializer(dateFormat));
}