private static Object parseJsonType()

in scim-spec/scim-spec-schema/src/main/java/org/apache/directory/scim/spec/filter/ExpressionBuildingListener.java [158:187]


  private static Object parseJsonType(String jsonValue) {
    if (jsonValue.startsWith("\"")) {
      String doubleEscaped = jsonValue.substring(1, jsonValue.length() - 1)
          // StringEscapeUtils follows the outdated JSON spec requiring "/" to be escaped, this could subtly break things
          .replaceAll("\\\\/", "\\\\\\\\/")
          // Just in case someone needs a single-quote with a backslash in front of it, this will be unnecessary with escapeJson()
          .replaceAll("\\\\'", "\\\\\\\\'");

      // TODO change this to escapeJson() when dependencies get upgraded
      return StringEscapeUtils.unescapeEcmaScript(doubleEscaped);
    } else if ("null".equals(jsonValue)) {
      return null;
    } else if ("true".equals(jsonValue)) {
      return true;
    } else if ("false".equals(jsonValue)) {
      return false;
    } else {
      try {
        if(jsonValue.contains(".")) {
          return Double.parseDouble(jsonValue);
        } else {
          return Integer.parseInt(jsonValue);
        }
      } catch (NumberFormatException e) {
        LOG.warn("Unable to parse a json number: " + jsonValue);
      }
    }

    throw new IllegalStateException("Unable to parse JSON Value");
  }