1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.security.oauth2.common.util;
18
19 import java.io.IOException;
20 import java.text.ParseException;
21 import java.text.SimpleDateFormat;
22 import java.util.Date;
23
24 import com.fasterxml.jackson.core.JsonParseException;
25 import com.fasterxml.jackson.core.JsonProcessingException;
26 import com.fasterxml.jackson.databind.DeserializationContext;
27 import com.fasterxml.jackson.databind.JsonDeserializer;
28
29
30
31
32
33
34
35 public class JsonDateDeserializer extends JsonDeserializer<Date> {
36
37 private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
38
39 @Override
40 public Date deserialize(com.fasterxml.jackson.core.JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException {
41 try {
42 synchronized (dateFormat) {
43 return dateFormat.parse(parser.getText());
44 }
45 }
46 catch (ParseException e) {
47 throw new JsonParseException("Could not parse date", parser.getCurrentLocation(), e);
48 }
49 }
50 }