public static <KeyType, ValueType> Map<KeyType, ValueType> toMap(
      JSONValue value,
      AbstractJsonEncoderDecoder<KeyType> keyEncoder,
      AbstractJsonEncoderDecoder<ValueType> valueEncoder,
      Style style) {
    if (value == null || value.isNull() != null) {
      return null;
    }

    switch (style) {
      case DEFAULT:
      case SIMPLE:
        {
          JSONObject object = value.isObject();
          if (object == null) {
            throw new DecodingException("Expected a json object, but was given: " + value);
          }

          HashMap<KeyType, ValueType> rc = new HashMap<KeyType, ValueType>(object.size() * 2);
          for (String key : object.keySet()) {
            rc.put(keyEncoder.decode(key), valueEncoder.decode(object.get(key)));
          }
          return rc;
        }
      case JETTISON_NATURAL:
        {
          JSONObject object = value.isObject();
          if (object == null) {
            throw new DecodingException("Expected a json object, but was given: " + value);
          }
          value = object.get("entry");
          if (value == null) {
            throw new DecodingException("Expected an entry array not found");
          }
          JSONArray entries = value.isArray();
          if (entries == null) {
            throw new DecodingException("Expected an entry array, but was given: " + value);
          }

          HashMap<KeyType, ValueType> rc = new HashMap<KeyType, ValueType>(object.size() * 2);
          for (int i = 0; i < entries.size(); i++) {
            JSONObject entry = entries.get(i).isObject();
            if (entry == null)
              throw new DecodingException("Expected an entry object, but was given: " + value);
            JSONValue key = entry.get("key");
            if (key == null) throw new DecodingException("Expected an entry key field not found");
            JSONString k = key.isString();
            if (k == null)
              throw new DecodingException(
                  "Expected an entry key to be a string, but was given: " + value);
            rc.put(keyEncoder.decode(k.stringValue()), valueEncoder.decode(entry.get("value")));
          }
          return rc;
        }
      default:
        throw new UnsupportedOperationException(
            "The encoding style is not yet supported: " + style.name());
    }
  }