use of javax.xml.datatype.XMLGregorianCalendar in project OpenAttestation by OpenAttestation.
the class SelectionBuilder method notAfter.
/**
* If you get NullPointerException make sure you have called selection()
* before calling this method.
*
* @param date
* @return
*/
public SelectionBuilder notAfter(Date date) {
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(date);
try {
XMLGregorianCalendar xmlCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
currentSelection.setNotAfter(xmlCalendar);
return this;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of javax.xml.datatype.XMLGregorianCalendar in project OpenAttestation by OpenAttestation.
the class SelectionBuilder method notBefore.
/**
* If you get NullPointerException make sure you have called selection()
* before calling this method.
*
* @param date
* @return
*/
public SelectionBuilder notBefore(Date date) {
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(date);
try {
XMLGregorianCalendar xmlCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
currentSelection.setNotBefore(xmlCalendar);
return this;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of javax.xml.datatype.XMLGregorianCalendar in project fastjson by alibaba.
the class Issue1023 method test_for_issue.
public void test_for_issue() throws Exception {
Date now = new Date();
GregorianCalendar gregorianCalendar = (GregorianCalendar) GregorianCalendar.getInstance();
gregorianCalendar.setTime(now);
XMLGregorianCalendar calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
String jsonString = JSON.toJSONString(calendar);
// success
calendar = JSON.parseObject(jsonString, XMLGregorianCalendar.class);
// debug看到是 Long 类型
Object toJSON1 = JSON.toJSON(calendar);
// 所以这里会报错:
// error: java.lang.ClassCastException: java.lang.Long cannot be cast to com.alibaba.fastjson.JSONObject
//JSONObject jsonObject = (JSONObject) JSON.toJSON(calendar);
// 所以 这里肯定会报错, 因为 jsonObject 不是JSONObject类型
//calendar = jsonObject.toJavaObject(XMLGregorianCalendar.class);
List<XMLGregorianCalendar> calendarList = new ArrayList<XMLGregorianCalendar>();
calendarList.add(calendar);
calendarList.add(calendar);
calendarList.add(calendar);
// debug 看到是 JSONArray 类型
Object toJSON2 = JSON.toJSON(calendarList);
// success: 通过 JSONArray.parseArray 方法可以正确转换
JSONArray jsonArray = (JSONArray) JSON.toJSON(calendarList);
jsonString = jsonArray.toJSONString();
List<XMLGregorianCalendar> calendarList1 = JSONArray.parseArray(jsonString, XMLGregorianCalendar.class);
// 通过 jsonArray.toJavaList 无法转换
// error: com.alibaba.fastjson.JSONException: can not cast to : javax.xml.datatype.XMLGregorianCalendar
List<XMLGregorianCalendar> calendarList2 = jsonArray.toJavaList(XMLGregorianCalendar.class);
assertNotNull(calendarList2);
assertEquals(3, calendarList2.size());
}
use of javax.xml.datatype.XMLGregorianCalendar 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 javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.
the class CheckTableHeader method createTriggerTooltip.
private String createTriggerTooltip() {
ObjectWrapper<O> wrapper = getModelObject();
PrismObject<O> obj = wrapper.getObject();
PrismContainer<TriggerType> container = obj.findContainer(ObjectType.F_TRIGGER);
if (container == null || container.isEmpty()) {
return null;
}
List<String> triggers = new ArrayList<>();
for (PrismContainerValue<TriggerType> val : container.getValues()) {
XMLGregorianCalendar time = val.getPropertyRealValue(TriggerType.F_TIMESTAMP, XMLGregorianCalendar.class);
if (time == null) {
triggers.add(getString("CheckTableHeader.triggerUnknownTime"));
} else {
triggers.add(getString("CheckTableHeader.triggerPlanned", WebComponentUtil.formatDate(time)));
}
}
return StringUtils.join(triggers, '\n');
}
Aggregations