Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame^] | 1 | package aQute.lib.json; |
| 2 | |
| 3 | import java.io.*; |
| 4 | import java.lang.reflect.*; |
| 5 | import java.text.*; |
| 6 | import java.util.*; |
| 7 | |
| 8 | public class DateHandler extends Handler { |
| 9 | final static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); |
| 10 | |
| 11 | @Override void encode(Encoder app, Object object, Map<Object, Type> visited) |
| 12 | throws IOException, Exception { |
| 13 | String s; |
| 14 | synchronized (sdf) { |
| 15 | s = sdf.format((Date) object); |
| 16 | } |
| 17 | StringHandler.string(app, s); |
| 18 | } |
| 19 | |
| 20 | @Override Object decode(String s) throws Exception { |
| 21 | synchronized (sdf) { |
| 22 | return sdf.parse(s); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | @Override Object decode(Number s) throws Exception { |
| 27 | return new Date(s.longValue()); |
| 28 | } |
| 29 | |
| 30 | } |