// This tests to see that the ObjectMapper serializes Date objects to the proper format @Test public void serializedDateDoesNotIncludeMilliseconds() throws JsonProcessingException { Date now = new Date(); // will be initialized to when it was allocated with millisecond precision SimpleDateFormat iso8601WithoutMilliseconds = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); iso8601WithoutMilliseconds.setTimeZone(TimeZone.getTimeZone("UTC")); String expectedDate = "\"" + iso8601WithoutMilliseconds.format(now) + "\""; JsonProvider provider = new JsonProvider(config); ObjectMapper mapper = provider.locateMapper(Object.class, MediaType.APPLICATION_JSON_TYPE); String serializedDate = mapper.writeValueAsString(now); assertTrue(serializedDate.equals(expectedDate)); }
public boolean sendAllItemsResponse() { ObjectNode event = JsonProvider.getAllItemsJson(); if (event != null) { sendMessage(event); return true; } else { System.err.println("Error getting all items"); return false; } }
public boolean sendViewBids(int userId) { ObjectNode event = JsonProvider.getViewBidsJson(userId); if (event != null) { sendMessage(event); return true; } else { System.err.println("Error getting viewBids"); return false; } }
public boolean sendLogInResponse(User user) { ObjectNode event = JsonProvider.getLoginJson(user); if (event != null) { sendMessage(event); return true; } else { System.err.println("Error logging in"); return false; } }
public boolean registerUser(User user) { ObjectNode event = JsonProvider.getRegisterJson(user); if (event.get("success").asBoolean()) { sendMessage(event); return true; } else { sendMessage(event); System.err.println("Error registering new user"); return false; } }
private boolean isEnabled(JsonProvider provider, SerializationFeature feature) { ObjectMapper mapper = provider.locateMapper(Object.class, MediaType.APPLICATION_JSON_TYPE); SerializationConfig sConfig = mapper.getSerializationConfig(); return sConfig.isEnabled(feature); }
public void sendConnectionId(String cid) { ObjectNode event = JsonProvider.getConnectionIdJson(cid); sendMessage(event); }
public void sendPlaceBid(Bid bid) { ObjectNode event = JsonProvider.getPlaceBidJson(bid); sendMessage(event); }
public void sendDeleteItem(int itemno) { ObjectNode event = JsonProvider.getDeleteItemJson(itemno); sendMessage(event); }
public void sendNewItem(Item item) { ObjectNode event = JsonProvider.getNewItemJson(item); sendMessage(event); }