JsonDateDeserializer extends JsonDeserializer<Date> { public static Date getDate(String text, JsonLocation loc) throws IOException { try { return new SimpleDateFormat(DATE_FORMATTER).parse(text); } catch (ParseException e) { throw new JsonParseException("Could not parse date:"+ text, loc, e); } }  @Override Date deserialize(JsonParser parser, DeserializationContext context); static Date getDate(String text, JsonLocation loc); static final String DATE_FORMATTER; }
@Test public void testParsing() throws IOException, ParseException { Date d = JsonDateDeserializer.getDate(testDateString, new JsonLocation(null, 22, 0, 0)); Assert.assertEquals(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").parse(testDateString).getTime(), (long) d.getTime()); }
@Test public void testParsingParallel() throws InterruptedException { Thread[] threadArray = new Thread[1000]; for (int i = 0; i < 1000; i++) { threadArray[i] = new Thread(() -> { try { Date d = JsonDateDeserializer.getDate(testDateString, new JsonLocation(null, 22, 0, 0)); if(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").parse(testDateString).getTime() != d.getTime()) { throw new Exception("Unexpected date"); } } catch (Exception e) { exceptionOccured = e; } }); } for (int i = 0; i < 1000; i++) { threadArray[i].start(); } for (int i = 0; i < 1000; i++) { threadArray[i].join(); } Assert.assertNull(exceptionOccured); }