本文整理汇总了Java中com.alibaba.fastjson.JSON.defaultLocale方法的典型用法代码示例。如果您正苦于以下问题:Java JSON.defaultLocale方法的具体用法?Java JSON.defaultLocale怎么用?Java JSON.defaultLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.JSON
的用法示例。
在下文中一共展示了JSON.defaultLocale方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_time
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_time() throws Exception {
long millis = System.currentTimeMillis();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", JSON.defaultLocale);
format.setTimeZone(JSON.defaultTimeZone);
String text = format.format(new java.util.Date(millis));
text += "T";
SimpleDateFormat format2 = new SimpleDateFormat("HH:mm:ss.SSS", JSON.defaultLocale);
format2.setTimeZone(JSON.defaultTimeZone);
text += format2.format(new java.util.Date(millis));
Assert.assertNull(JSON.parseObject("null", Time.class));
Assert.assertNull(JSON.parseObject("\"\"", Time.class));
Assert.assertNull(JSON.parseArray("null", Time.class));
Assert.assertNull(JSON.parseArray("[null]", Time.class).get(0));
Assert.assertNull(JSON.parseObject("{\"value\":null}", VO.class).getValue());
Assert.assertEquals(new Time(millis), JSON.parseObject("" + millis, Time.class));
Assert.assertEquals(new Time(millis), JSON.parseObject("{\"@type\":\"java.sql.Time\",\"val\":" + millis + "}", Time.class));
Assert.assertEquals(new Time(millis), JSON.parseObject("\"" + millis + "\"", Time.class));
Assert.assertEquals(new Time(millis), JSON.parseObject("\"" + text + "\"", Time.class));
//System.out.println(JSON.toJSONString(new Time(millis), SerializerFeature.WriteClassName));
}
示例2: test_0
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_0() throws Exception {
Date date = new Date();
String text = JSON.toJSONString(date, mapping);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", JSON.defaultLocale);
format.setTimeZone(JSON.defaultTimeZone);
SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd", JSON.defaultLocale);
format2.setTimeZone(JSON.defaultTimeZone);
Assert.assertEquals(JSON.toJSONString(format.format(date)), text);
Assert.assertEquals(JSON.toJSONString(format2.format(date)), text);
}
示例3: test_codec_no_asm
import com.alibaba.fastjson.JSON; //导入方法依赖的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_0
import com.alibaba.fastjson.JSON; //导入方法依赖的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);
}
示例5: test_date
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_date() throws Exception {
String text = "{\"value\":\"1979-07-14\"}";
VO vo = JSON.parseObject(text, VO.class);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", JSON.defaultLocale);
dateFormat.setTimeZone(JSON.defaultTimeZone);
Assert.assertEquals(vo.getValue(), dateFormat.parse("1979-07-14").getTime());
}
示例6: test_codec_no_asm
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_codec_no_asm() throws Exception {
V0 v = new V0();
v.setValue(new Date());
SerializeConfig mapping = new SerializeConfig();
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);
}
示例7: test_codec_asm
import com.alibaba.fastjson.JSON; //导入方法依赖的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);
}
示例8: setUp
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
protected void setUp() throws Exception {
JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
JSON.defaultLocale = Locale.CHINA;
}