Example usage for org.json JSONObject valueToString

List of usage examples for org.json JSONObject valueToString

Introduction

In this page you can find the example usage for org.json JSONObject valueToString.

Prototype

static String valueToString(Object value) throws JSONException 

Source Link

Document

Make a JSON text of an Object value.

Usage

From source file:com.unboundid.scim.sdk.SCIMFilter.java

/**
 * Append the string representation of the filter to the provided buffer.
 *
 * @param builder  The buffer to which the string representation of the
 *                 filter is to be appended.
 *///from   w  ww.j av a  2 s . c o  m
public void toString(final StringBuilder builder) {
    switch (filterType) {
    case AND:
    case OR:
        builder.append('(');

        for (int i = 0; i < filterComponents.size(); i++) {
            if (i != 0) {
                builder.append(' ');
                builder.append(filterType);
                builder.append(' ');
            }

            builder.append(filterComponents.get(i));
        }

        builder.append(')');
        break;

    case EQUALITY:
    case CONTAINS:
    case STARTS_WITH:
    case GREATER_THAN:
    case GREATER_OR_EQUAL:
    case LESS_THAN:
    case LESS_OR_EQUAL:
        builder.append(filterAttribute);
        builder.append(' ');
        builder.append(filterType);
        builder.append(' ');

        if (quoteFilterValue) {
            try {
                builder.append(JSONObject.valueToString(filterValue));
            } catch (JSONException e) {
                Debug.debugException(e);
            }
        } else {
            builder.append(filterValue);
        }
        break;

    case PRESENCE:
        builder.append(filterAttribute);
        builder.append(' ');
        builder.append(filterType);
        break;
    }
}