Search in sources :

Example 16 with JSONException

use of com.unboundid.util.json.JSONException in project ldapsdk by pingidentity.

the class EqualsAnyJSONObjectFilter method decodeFilter.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
protected EqualsAnyJSONObjectFilter decodeFilter(@NotNull final JSONObject filterObject) throws JSONException {
    final List<String> fieldPath = getStrings(filterObject, FIELD_FIELD_PATH, false, null);
    final boolean isCaseSensitive = getBoolean(filterObject, FIELD_CASE_SENSITIVE, false);
    final JSONValue arrayValue = filterObject.getField(FIELD_VALUES);
    if (arrayValue instanceof JSONArray) {
        return new EqualsAnyJSONObjectFilter(fieldPath, ((JSONArray) arrayValue).getValues(), isCaseSensitive);
    } else {
        throw new JSONException(ERR_OBJECT_FILTER_VALUE_NOT_ARRAY.get(String.valueOf(filterObject), FILTER_TYPE, FIELD_VALUES));
    }
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONArray(com.unboundid.util.json.JSONArray) JSONException(com.unboundid.util.json.JSONException) JSONString(com.unboundid.util.json.JSONString) NotNull(com.unboundid.util.NotNull)

Example 17 with JSONException

use of com.unboundid.util.json.JSONException in project ldapsdk by pingidentity.

the class JSONLDAPResultWriter method toJSON.

/**
 * Encodes the provided search result reference as a JSON object.
 *
 * @param  ref  The search result reference to be encoded as a JSON object.
 *              It must not be {@code null}.
 *
 * @return  The JSON object containing the encoded representation of the
 *          search result reference.
 */
@NotNull()
public static JSONObject toJSON(@NotNull final SearchResultReference ref) {
    try {
        final JSONBuffer jsonBuffer = new JSONBuffer();
        toJSON(ref, jsonBuffer);
        return jsonBuffer.toJSONObject();
    } catch (final JSONException e) {
        // This should never happen.
        Debug.debugException(e);
        throw new LDAPRuntimeException(new LDAPException(ResultCode.ENCODING_ERROR, e.getMessage(), e));
    }
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) JSONBuffer(com.unboundid.util.json.JSONBuffer) JSONException(com.unboundid.util.json.JSONException) LDAPRuntimeException(com.unboundid.ldap.sdk.LDAPRuntimeException) NotNull(com.unboundid.util.NotNull)

Aggregations

JSONException (com.unboundid.util.json.JSONException)17 NotNull (com.unboundid.util.NotNull)10 JSONString (com.unboundid.util.json.JSONString)10 JSONObject (com.unboundid.util.json.JSONObject)9 JSONArray (com.unboundid.util.json.JSONArray)5 JSONField (com.unboundid.util.json.JSONField)5 Test (org.testng.annotations.Test)5 LDAPException (com.unboundid.ldap.sdk.LDAPException)4 JSONValue (com.unboundid.util.json.JSONValue)4 LDAPRuntimeException (com.unboundid.ldap.sdk.LDAPRuntimeException)3 JSONBuffer (com.unboundid.util.json.JSONBuffer)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 LDAPSDKUsageException (com.unboundid.util.LDAPSDKUsageException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Pattern (java.util.regex.Pattern)1