use of com.fasterxml.jackson.databind.util.ISO8601DateFormat in project graphhopper by graphhopper.
the class GraphHopperServletModule method createObjectMapper.
@Provides
@Singleton
ObjectMapper createObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setDateFormat(new ISO8601DateFormat());
objectMapper.registerModule(new JtsModule());
SimpleModule pathDetailModule = new SimpleModule();
pathDetailModule.addSerializer(PathDetail.class, new PathDetailSerializer());
pathDetailModule.addDeserializer(PathDetail.class, new PathDetailDeserializer());
objectMapper.registerModule(pathDetailModule);
// Because VirtualEdgeIteratorState has getters which throw Exceptions.
// http://stackoverflow.com/questions/35359430/how-to-make-jackson-ignore-properties-if-the-getters-throw-exceptions
objectMapper.registerModule(new SimpleModule().setSerializerModifier(new BeanSerializerModifier() {
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
return beanProperties.stream().map(bpw -> new BeanPropertyWriter(bpw) {
@Override
public void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception {
try {
super.serializeAsField(bean, gen, prov);
} catch (Exception e) {
// Ignoring expected exception, see above.
}
}
}).collect(Collectors.toList());
}
}));
return objectMapper;
}
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 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;
}
use of com.fasterxml.jackson.databind.util.ISO8601DateFormat in project JMRI by JMRI.
the class JsonTimeHttpService method doGet.
@Override
public JsonNode doGet(String type, String name, Locale locale) throws JsonException {
ObjectNode root = this.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;
}
Aggregations