use of com.unboundid.util.json.JSONObject in project ldapsdk by pingidentity.
the class JSONObjectExactMatchingRule method valuesMatch.
/**
* {@inheritDoc}
*/
@Override()
public boolean valuesMatch(@NotNull final ASN1OctetString value1, @NotNull final ASN1OctetString value2) throws LDAPException {
final JSONObject o1;
try {
o1 = new JSONObject(value1.stringValue());
} catch (final JSONException e) {
Debug.debugException(e);
throw new LDAPException(ResultCode.INVALID_ATTRIBUTE_SYNTAX, e.getMessage(), e);
}
final JSONObject o2;
try {
o2 = new JSONObject(value2.stringValue());
} catch (final JSONException e) {
Debug.debugException(e);
throw new LDAPException(ResultCode.INVALID_ATTRIBUTE_SYNTAX, e.getMessage(), e);
}
return o1.equals(o2, false, true, false);
}
use of com.unboundid.util.json.JSONObject in project ldapsdk by pingidentity.
the class JSONObjectFilter method getFilters.
/**
* Retrieves the value of the specified field from the provided JSON object as
* a list of JSON object filters. The specified field must be a top-level
* field in the JSON object and it must have a value that is an array of
* JSON objects that represent valid JSON object filters.
*
* @param o The JSON object to examine. It must not be
* {@code null}.
* @param fieldName The name of a top-level field in the JSON object that is
* expected to have a value that is an array of JSON
* objects that represent valid JSON object filters. It
* must not be {@code null}.
*
* @return The list of JSON object filters retrieved from the JSON object.
*
* @throws JSONException If the object doesn't have the specified field, or
* if the value of that field is not an array of
* JSON objects that represent valid JSON object
* filters.
*/
@NotNull()
protected List<JSONObjectFilter> getFilters(@NotNull final JSONObject o, @NotNull final String fieldName) throws JSONException {
final JSONValue value = o.getField(fieldName);
if (value == null) {
throw new JSONException(ERR_OBJECT_FILTER_MISSING_REQUIRED_FIELD.get(String.valueOf(o), getFilterType(), fieldName));
}
if (!(value instanceof JSONArray)) {
throw new JSONException(ERR_OBJECT_FILTER_VALUE_NOT_ARRAY.get(String.valueOf(o), getFilterType(), fieldName));
}
final List<JSONValue> values = ((JSONArray) value).getValues();
final ArrayList<JSONObjectFilter> filterList = new ArrayList<>(values.size());
for (final JSONValue arrayValue : values) {
if (!(arrayValue instanceof JSONObject)) {
throw new JSONException(ERR_OBJECT_FILTER_ARRAY_ELEMENT_NOT_OBJECT.get(String.valueOf(o), getFilterType(), fieldName));
}
final JSONObject filterObject = (JSONObject) arrayValue;
try {
filterList.add(decode(filterObject));
} catch (final JSONException e) {
Debug.debugException(e);
throw new JSONException(ERR_OBJECT_FILTER_ARRAY_ELEMENT_NOT_FILTER.get(String.valueOf(o), getFilterType(), String.valueOf(filterObject), fieldName, e.getMessage()), e);
}
}
return filterList;
}
use of com.unboundid.util.json.JSONObject in project ldapsdk by pingidentity.
the class LessThanJSONObjectFilter method toJSONObject.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public JSONObject toJSONObject() {
final LinkedHashMap<String, JSONValue> fields = new LinkedHashMap<>(StaticUtils.computeMapCapacity(6));
fields.put(FIELD_FILTER_TYPE, new JSONString(FILTER_TYPE));
if (field.size() == 1) {
fields.put(FIELD_FIELD_PATH, new JSONString(field.get(0)));
} else {
final ArrayList<JSONValue> fieldNameValues = new ArrayList<>(field.size());
for (final String s : field) {
fieldNameValues.add(new JSONString(s));
}
fields.put(FIELD_FIELD_PATH, new JSONArray(fieldNameValues));
}
fields.put(FIELD_VALUE, value);
if (allowEquals) {
fields.put(FIELD_ALLOW_EQUALS, JSONBoolean.TRUE);
}
if (matchAllElements) {
fields.put(FIELD_MATCH_ALL_ELEMENTS, JSONBoolean.TRUE);
}
if (caseSensitive) {
fields.put(FIELD_CASE_SENSITIVE, JSONBoolean.TRUE);
}
return new JSONObject(fields);
}
use of com.unboundid.util.json.JSONObject in project ldapsdk by pingidentity.
the class NegateJSONObjectFilter method toJSONObject.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public JSONObject toJSONObject() {
final LinkedHashMap<String, JSONValue> fields = new LinkedHashMap<>(StaticUtils.computeMapCapacity(2));
fields.put(FIELD_FILTER_TYPE, new JSONString(FILTER_TYPE));
fields.put(FIELD_NEGATE_FILTER, negateFilter.toJSONObject());
return new JSONObject(fields);
}
use of com.unboundid.util.json.JSONObject in project ldapsdk by pingidentity.
the class ObjectMatchesJSONObjectFilter method toJSONObject.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public JSONObject toJSONObject() {
final LinkedHashMap<String, JSONValue> fields = new LinkedHashMap<>(StaticUtils.computeMapCapacity(3));
fields.put(FIELD_FILTER_TYPE, new JSONString(FILTER_TYPE));
if (field.size() == 1) {
fields.put(FIELD_FIELD_PATH, new JSONString(field.get(0)));
} else {
final ArrayList<JSONValue> fieldNameValues = new ArrayList<>(field.size());
for (final String s : field) {
fieldNameValues.add(new JSONString(s));
}
fields.put(FIELD_FIELD_PATH, new JSONArray(fieldNameValues));
}
fields.put(FIELD_FILTER, filter.toJSONObject());
return new JSONObject(fields);
}
Aggregations