blob: 85aad12edfc5a5c3aff677e46dc80269faf82fe1 [file] [log] [blame]
Stuart McCullochbb014372012-06-07 21:57:32 +00001package aQute.lib.json;
2
3import java.io.*;
4import java.lang.reflect.*;
5import java.util.*;
6
7public class EnumHandler extends Handler {
8 @SuppressWarnings("rawtypes")
Stuart McCulloch2286f232012-06-15 13:27:53 +00009 final Class type;
Stuart McCullochbb014372012-06-07 21:57:32 +000010
Stuart McCulloch2286f232012-06-15 13:27:53 +000011 public EnumHandler(Class< ? > type) {
Stuart McCullochbb014372012-06-07 21:57:32 +000012 this.type = type;
13 }
14
Stuart McCulloch2286f232012-06-15 13:27:53 +000015 @Override
16 void encode(Encoder app, Object object, Map<Object,Type> visited) throws IOException, Exception {
Stuart McCullochbb014372012-06-07 21:57:32 +000017 StringHandler.string(app, object.toString());
18 }
19
Stuart McCulloch2286f232012-06-15 13:27:53 +000020 @SuppressWarnings("unchecked")
21 Object decode(String s) throws Exception {
Stuart McCullochbb014372012-06-07 21:57:32 +000022 return Enum.valueOf(type, s);
23 }
24
25}