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.util.*; |
| 6 | |
| 7 | public class EnumHandler extends Handler { |
| 8 | @SuppressWarnings("rawtypes") |
| 9 | final Class type; |
| 10 | |
| 11 | public EnumHandler(Class<?> type) { |
| 12 | this.type = type; |
| 13 | } |
| 14 | |
| 15 | @Override void encode(Encoder app, Object object, Map<Object, Type> visited) |
| 16 | throws IOException, Exception { |
| 17 | StringHandler.string(app, object.toString()); |
| 18 | } |
| 19 | |
| 20 | @SuppressWarnings("unchecked") Object decode(String s) throws Exception { |
| 21 | return Enum.valueOf(type, s); |
| 22 | } |
| 23 | |
| 24 | } |