use of com.fasterxml.jackson.databind.util.ISO8601DateFormat in project fastjson by alibaba.
the class JSONSerializerDeprecatedTest method test_.
public void test_() throws Exception {
JSONSerializer ser = new JSONSerializer(new SerializeConfig());
ser.setDateFormat(new ISO8601DateFormat());
Assert.assertEquals(null, ser.getDateFormatPattern());
ser.close();
}
use of com.fasterxml.jackson.databind.util.ISO8601DateFormat in project jackson-databind by FasterXML.
the class DateDeserializationTest method testISO8601Directly.
// Based on an external report; was throwing an exception for second case here
public void testISO8601Directly() throws Exception {
final String TIME_STR = "2015-01-21T08:56:13.533+0000";
Date d = MAPPER.readValue(quote(TIME_STR), Date.class);
assertNotNull(d);
ISO8601DateFormat f = new ISO8601DateFormat();
Date d2 = f.parse(TIME_STR);
assertNotNull(d2);
assertEquals(d.getTime(), d2.getTime());
}
use of com.fasterxml.jackson.databind.util.ISO8601DateFormat in project JMRI by JMRI.
the class JsonUtil method getTime.
@Deprecated
public static JsonNode getTime(Locale locale) throws JsonException {
ObjectNode root = mapper.createObjectNode();
root.put(TYPE, TIME);
ObjectNode data = root.putObject(DATA);
data.put(TIME, new ISO8601DateFormat().format(InstanceManager.getDefault(jmri.Timebase.class).getTime()));
data.put(RATE, InstanceManager.getDefault(jmri.Timebase.class).getRate());
data.put(STATE, InstanceManager.getDefault(jmri.Timebase.class).getRun() ? ON : OFF);
return root;
}
use of com.fasterxml.jackson.databind.util.ISO8601DateFormat in project JMRI by JMRI.
the class TrainCommon method getISO8601Date.
public static String getISO8601Date(boolean isModelYear) {
Calendar calendar = Calendar.getInstance();
// use the JMRI Timebase (which may be a fast clock).
calendar.setTime(jmri.InstanceManager.getDefault(jmri.Timebase.class).getTime());
if (isModelYear && !Setup.getYearModeled().isEmpty()) {
try {
calendar.set(Calendar.YEAR, Integer.parseInt(Setup.getYearModeled().trim()));
} catch (NumberFormatException e) {
return Setup.getYearModeled();
}
}
return (new ISO8601DateFormat()).format(calendar.getTime());
}
use of com.fasterxml.jackson.databind.util.ISO8601DateFormat in project JMRI by JMRI.
the class JsonRosterHttpService method getRosterEntry.
/**
* Returns the JSON representation of a roster entry.
*
* Note that this returns, for images and icons, a URL relative to the root
* folder of the JMRI server. It is expected that clients will fill in the
* server IP address and port as they know it to be.
*
* @param locale the client's Locale
* @param entry A RosterEntry that may or may not be in the roster.
* @return a roster entry in JSON notation
*/
public JsonNode getRosterEntry(Locale locale, @Nonnull RosterEntry entry) {
ObjectNode root = this.mapper.createObjectNode();
root.put(TYPE, JsonRoster.ROSTER_ENTRY);
ObjectNode data = root.putObject(DATA);
data.put(NAME, entry.getId());
data.put(ADDRESS, entry.getDccAddress());
data.put(IS_LONG_ADDRESS, entry.isLongAddress());
data.put(ROAD, entry.getRoadName());
data.put(NUMBER, entry.getRoadNumber());
data.put(MFG, entry.getMfg());
data.put(DECODER_MODEL, entry.getDecoderModel());
data.put(DECODER_FAMILY, entry.getDecoderFamily());
data.put(MODEL, entry.getModel());
data.put(COMMENT, entry.getComment());
data.put(MAX_SPD_PCT, Integer.toString(entry.getMaxSpeedPCT()));
data.put(IMAGE, (entry.getImagePath() != null) ? "/" + JsonRoster.ROSTER + "/" + entry.getId() + "/" + IMAGE : null);
data.put(ICON, (entry.getIconPath() != null) ? "/" + JsonRoster.ROSTER + "/" + entry.getId() + "/" + ICON : null);
data.put(SHUNTING_FUNCTION, entry.getShuntingFunction());
data.put(JsonRoster.DATE_MODIFIED, (entry.getDateModified() != null) ? new ISO8601DateFormat().format(entry.getDateModified()) : null);
ArrayNode labels = data.putArray(FUNCTION_KEYS);
for (int i = 0; i <= entry.getMAXFNNUM(); i++) {
ObjectNode label = mapper.createObjectNode();
label.put(NAME, F + i);
label.put(LABEL, entry.getFunctionLabel(i));
label.put(LOCKABLE, entry.getFunctionLockable(i));
label.put(ICON, (entry.getFunctionImage(i) != null) ? "/" + JsonRoster.ROSTER + "/" + entry.getId() + "/" + F + i + "/" + ICON : null);
label.put(SELECTED_ICON, (entry.getFunctionSelectedImage(i) != null) ? "/" + JsonRoster.ROSTER + "/" + entry.getId() + "/" + F + i + "/" + SELECTED_ICON : null);
labels.add(label);
}
ArrayNode attributes = data.putArray(JsonRoster.ATTRIBUTES);
entry.getAttributes().stream().forEach((name) -> {
ObjectNode attribute = mapper.createObjectNode();
attribute.put(NAME, name);
attribute.put(VALUE, entry.getAttribute(name));
attributes.add(attribute);
});
ArrayNode rga = data.putArray(JsonRoster.ROSTER_GROUPS);
entry.getGroups().stream().forEach((group) -> {
rga.add(group.getName());
});
return root;
}
Aggregations