use of com.alibaba.fastjson.JSONObject in project fastjson by alibaba.
the class Bug_for_issue_320 method test_for_issue.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void test_for_issue() throws Exception {
Map map = new HashMap();
map.put(1001L, "aaa");
String text = JSON.toJSONString(map);
Assert.assertEquals("{1001:\"aaa\"}", text);
JSONObject obj = JSON.parseObject(text);
Assert.assertEquals("aaa", obj.get("1001"));
}
use of com.alibaba.fastjson.JSONObject in project fastjson by alibaba.
the class XMLGregorianCalendarTest method test_for_issue.
public void test_for_issue() throws Exception {
GregorianCalendar gregorianCalendar = (GregorianCalendar) GregorianCalendar.getInstance();
XMLGregorianCalendar calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
String text = JSON.toJSONString(calendar);
Assert.assertEquals(Long.toString(gregorianCalendar.getTimeInMillis()), text);
XMLGregorianCalendar calendar1 = JSON.parseObject(text, XMLGregorianCalendar.class);
assertEquals(calendar.toGregorianCalendar().getTimeInMillis(), calendar1.toGregorianCalendar().getTimeInMillis());
JSONObject jsonObject = new JSONObject();
jsonObject.put("calendar", calendar);
String json = JSON.toJSONString(jsonObject);
Model model = JSON.parseObject(json).toJavaObject(Model.class);
assertEquals(calendar.toGregorianCalendar().getTimeInMillis(), model.calendar.toGregorianCalendar().getTimeInMillis());
}
use of com.alibaba.fastjson.JSONObject in project fastjson by alibaba.
the class Issue978 method test_for_issue.
public void test_for_issue() throws Exception {
Model model = new Model();
model.date = new Date(1483413683714L);
JSONObject obj = (JSONObject) JSON.toJSON(model);
assertEquals("{\"date\":\"2017-01-03 11:21:23\"}", obj.toJSONString());
}
use of com.alibaba.fastjson.JSONObject in project fastjson by alibaba.
the class Issue_611 method test_for_issue.
public void test_for_issue() throws Exception {
String text = "{\"priority\":1}";
JSONObject obj = JSON.parseObject(text);
Assert.assertEquals(1, obj.getInteger("priority").intValue());
Assert.assertEquals(1, obj.getIntValue("priority"));
}
use of com.alibaba.fastjson.JSONObject in project fastjson by alibaba.
the class Issue_748 method testJsonObjectWithClassName.
public void testJsonObjectWithClassName() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("key1", "value1");
jsonObject.put("key2", "value2");
DataObject dataObject = new DataObject();
dataObject.setValue(jsonObject);
String jsonStr = JSON.toJSONString(dataObject, SerializerFeature.QuoteFieldNames, SerializerFeature.SkipTransientField, SerializerFeature.WriteClassName);
// System.out.println("parse之前:" + jsonStr);
DataObject obj = (DataObject) JSON.parse(jsonStr, Feature.IgnoreNotMatch);
Assert.assertNotNull(obj.value);
Assert.assertNotNull(obj.value.get("key1"));
Assert.assertNotNull(obj.value.get("key2"));
}
Aggregations