Example usage for com.google.gwt.json.client JSONValue isBoolean

List of usage examples for com.google.gwt.json.client JSONValue isBoolean

Introduction

In this page you can find the example usage for com.google.gwt.json.client JSONValue isBoolean.

Prototype

public JSONBoolean isBoolean() 

Source Link

Document

Returns a non-null reference if this JSONValue is really a JSONBoolean.

Usage

From source file:com.google.gson.JsonElement.java

License:Apache License

static JsonElement wrap(JSONValue value) {
    if (value == null)
        return null;
    if (value.isNull() != null)
        return JsonNull.createJsonNull();
    if (value.isBoolean() != null || value.isNumber() != null || value.isString() != null)
        return new JsonPrimitive(value);
    if (value.isObject() != null)
        return new JsonObject(value.isObject());
    if (value.isArray() != null)
        return new JsonArray(value.isArray());

    throw new IllegalArgumentException();
}

From source file:com.googlecode.gwtphonegap.client.contacts.browser.ContactBrowserImpl.java

License:Apache License

private static boolean getFieldAsBoolean(JSONValue field) {
    return field.isBoolean() != null ? field.isBoolean().booleanValue() : false;
}

From source file:com.guit.client.jsorm.BooleanSerializer.java

License:Apache License

@Override
protected Boolean deserializeJson(JSONValue o) {
    return o.isBoolean().booleanValue();
}

From source file:com.hunchee.haystack.client.utils.JsonConverter.java

License:Open Source License

/**
 * Decodes a JSONObject to a map./*from   w w  w .j  ava  2  s. c  o m*/
 *
 * @param jso the JSONObject
 * @return the map
 */
public static Map<String, Object> decode(JSONObject jso) {
    Map<String, Object> map = new LinkedHashMap<String, Object>();
    for (String key : jso.keySet()) {
        JSONValue j = jso.get(key);
        if (j.isObject() != null) {
            map.put(key, decode(j.isObject()));
        } else if (j.isArray() != null) {
            map.put(key, decodeToList(j.isArray()));
        } else if (j.isBoolean() != null) {
            map.put(key, j.isBoolean().booleanValue());
        } else if (j.isNumber() != null) {
            map.put(key, j.isNumber().doubleValue());
        } else if (j.isString() != null) {
            //map.put(key, decodeValue(j.isString().stringValue()));
            map.put(key, j.isString().stringValue());
        }
    }
    return map;
}

From source file:com.hunchee.haystack.client.utils.JsonConverter.java

License:Open Source License

protected static List<Object> decodeToList(JSONArray array) {
    List<Object> list = new ArrayList<Object>();
    for (int i = 0; i < array.size(); i++) {
        JSONValue v = array.get(i);
        if (v.isObject() != null) {
            list.add(decode(v.isObject()));
        } else if (v.isArray() != null) {
            list.add(decodeToList(v.isArray()));
        } else if (v.isNull() != null) {
            list.add(null);/*from www .  ja v a  2 s  . c om*/
        } else if (v.isNumber() != null) {
            list.add(v.isNumber().doubleValue());
        } else if (v.isBoolean() != null) {
            list.add(v.isBoolean().booleanValue());
        } else if (v.isString() != null) {
            //                list.add(decodeValue(v.isString().stringValue()));
            list.add(v.isString().stringValue());
        }
    }

    return list;
}

From source file:com.kk_electronic.kkportal.core.rpc.jsonformat.JsonBoolean.java

License:Open Source License

@Override
public Boolean fromJson(JSONValue jsonValue, List<Class<?>> subtypes, FrameEncoder<JSONValue> encoder)
        throws UnableToDeserialize {
    JSONBoolean number = jsonValue.isBoolean();
    if (number == null)
        throw new UnableToDeserialize("Expected json number");
    return number.booleanValue();
}

From source file:com.kk_electronic.kkportal.core.rpc.SimpleEncoder.java

License:Open Source License

private static Object convert(JSONValue y, ObjectHelper objectHelper) {
    if (y.isArray() != null)
        return convert(y.isArray(), objectHelper);
    if (y.isObject() != null)
        return convert(y.isObject(), objectHelper);
    if (y.isBoolean() != null)
        return y.isBoolean().booleanValue();
    if (y.isString() != null)
        return y.isString().stringValue();
    if (y.isNumber() != null)
        return y.isNumber().doubleValue();
    if (y.isNull() != null)
        return null;
    throw new RuntimeException("Could not convert");
}

From source file:com.mcherm.zithiacharsheet.client.model.JSONDeserializer.java

License:Apache License

protected void updateFromField(JSONObject parent, String fieldName, SettableBooleanValue settableBooleanValue) {
    JSONValue valueValue = notNull(parent.get(fieldName));
    JSONBoolean valueBool = notNull(valueValue.isBoolean());
    settableBooleanValue.setValue(valueBool.booleanValue());
}

From source file:com.palmagroup.gwt.orders.client.gin.JsonConverter.java

License:Open Source License

/**
 * Decodes a JSONObject to a map.//from  w ww  .  ja  v a 2s. co  m
 * 
 * @param jso
 *            the JSONObject
 * @return the map
 */
public static Map<String, Object> decode(JSONObject jso) {
    Map<String, Object> map = new FastMap<Object>();
    for (String key : jso.keySet()) {
        JSONValue j = jso.get(key);
        if (j.isObject() != null) {
            map.put(key, decode(j.isObject()));
        } else if (j.isArray() != null) {
            map.put(key, decodeToList(j.isArray()));
        } else if (j.isBoolean() != null) {
            map.put(key, j.isBoolean().booleanValue());
        } else if (j.isNumber() != null) {
            map.put(key, j.isNumber().doubleValue());
        } else if (j.isString() != null) {
            map.put(key, decodeValue(j.isString().stringValue()));
        }
    }
    return map;
}

From source file:com.parabay.client.utils.JSONCodec.java

License:Apache License

/**
 * Converts a JSONValue to a Java object.
 * //w ww .ja va  2 s  . c  o  m
 * @param value
 * @return
 */
private Object buildJavaObjectFromJSONValue(JSONValue value) {
    if (value.isNull() != null) {
        return null;
    }
    if (value.isBoolean() != null) {
        return Boolean.valueOf(value.isBoolean().booleanValue());
    }
    if (value.isString() != null) {
        return value.isString().stringValue();
    }
    if (value.isNumber() != null) {
        return buildNumber(value.isNumber().toString());
    }
    if (value.isArray() != null) {
        return buildJavaArrayFromJSONArray(value.isArray());
    }
    if (value.isObject() != null) {
        return buildJavaMapFromJSONObject(value.isObject());
    }
    return null;
}