blob: 784fcbe99e65687a095581f977f9c493ff201c42 [file] [log] [blame]
Stuart McCullochbb014372012-06-07 21:57:32 +00001package aQute.lib.json;
2
3import java.io.*;
4import java.lang.reflect.*;
5import java.text.*;
6import java.util.*;
7
8public class DateHandler extends Handler {
9 final static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
10
Stuart McCulloch2286f232012-06-15 13:27:53 +000011 @Override
12 void encode(Encoder app, Object object, Map<Object,Type> visited) throws IOException, Exception {
Stuart McCullochbb014372012-06-07 21:57:32 +000013 String s;
14 synchronized (sdf) {
15 s = sdf.format((Date) object);
16 }
17 StringHandler.string(app, s);
18 }
19
Stuart McCulloch2286f232012-06-15 13:27:53 +000020 @Override
21 Object decode(String s) throws Exception {
Stuart McCullochbb014372012-06-07 21:57:32 +000022 synchronized (sdf) {
23 return sdf.parse(s);
24 }
25 }
26
Stuart McCulloch2286f232012-06-15 13:27:53 +000027 @Override
28 Object decode(Number s) throws Exception {
Stuart McCullochbb014372012-06-07 21:57:32 +000029 return new Date(s.longValue());
30 }
31
32}