title: Python: How to decode enum type from json
body: <pre><code>class MSG_TYPE(IntEnum):
      REQUEST = 0
      GRANT = 1
      RELEASE = 2
      FAIL = 3
      INQUIRE = 4
      YIELD = 5
  
      def __json__(self):
          return str(self)
  
  class MessageEncoder(JSONEncoder):
      def default(self, obj):
          return obj.__json__()
  
  class Message(object):
      def __init__(self, msg_type, src, dest, data):
          self.msg_type = msg_type
          self.src = src
          self.dest = dest
          self.data = data
  
      def __json__(self):
          return dict (\
              msg_type=self.msg_type, \
              src=self.src, \
              dest=self.dest, \
              data=self.data,\
              )
  
      def ToJSON(self):
          return json.dumps(self, cls=MessageEncoder)
  
  msg = Message(msg_type=MSG_TYPE.FAIL, src=0, dest=1, data="hello world")
  encoded_msg = msg.ToJSON()
  decoded_msg = yaml.load(encoded_msg)
  print type(decoded_msg['msg_type'])
  </code></pre>
  
  <p>When calling <code>print type(decoded_msg['msg_type'])</code>, I get the result <code>&lt;type 'str'&gt;</code> instead of the original <code>MSG_TYPTE</code> type. I feel like I should also write a custom json decoder but kind of confused how to do that. Any ideas? Thanks.</p>