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

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

Introduction

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

Prototype

public JSONNumber isNumber() 

Source Link

Document

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

Usage

From source file:com.github.ligangty.common.highconvert.Axis.java

License:Apache License

private Number getNumberFromJSONObject(JSONObject jsonObject, String key) {
    JSONValue jsonValue = jsonObject.get(key);
    if (jsonValue != null && jsonValue.isNumber() != null) {
        return jsonValue.isNumber().doubleValue();
    }/* w w  w. j  av a  2 s  .  c  o m*/
    return null;
}

From source file:com.google.debugging.sourcemap.SourceMapObject.java

License:Apache License

private static int getNumber(JSONValue value, int def) {
    if (value == null) {
        return def;
    }//from   w  w  w.  j  a  v  a 2  s  . c o m
    JSONNumber number = value.isNumber();
    if (number == null) {
        return def;
    }
    return (int) number.doubleValue();
}

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

public static Contact fromJSON(ContactsBrowserImpl controller, JSONObject jsonContact) {
    ContactBrowserImpl contact = new ContactBrowserImpl(controller);

    // simple fields
    contact.setId(getFieldAsString(jsonContact.get(FIELD_ID)));
    contact.setDisplayName(getFieldAsString(jsonContact.get(CONTACT_DISPLAY_NAME)));
    contact.setNickName(getFieldAsString(jsonContact.get(CONTACT_NICK_NAME)));
    contact.setNote(getFieldAsString(jsonContact.get(CONTACT_NOTE)));

    // birthday//from w w w.  j  a v a2 s .c om
    JSONValue dateValue = jsonContact.get(CONTACT_BIRTHDAY);
    if (dateValue != null && dateValue.isNumber() != null) {
        contact.setBirthDay(new Date((long) dateValue.isNumber().doubleValue()));
    }

    // contact fields
    JSONArray phoneNumberArray = jsonContact.get(CONTACT_PHONE_NUMBERS).isArray();
    LightArray<ContactField> phoneNumbers = getContactFieldsForArray(phoneNumberArray);
    contact.setPhoneNumbers(phoneNumbers);

    JSONArray emailsArray = jsonContact.get(CONTACT_EMAILS).isArray();
    LightArray<ContactField> emails = getContactFieldsForArray(emailsArray);
    contact.setEmails(emails);

    JSONArray imsArray = jsonContact.get(CONTACT_IMS).isArray();
    LightArray<ContactField> ims = getContactFieldsForArray(imsArray);
    contact.setIms(ims);

    JSONArray photosArray = jsonContact.get(CONTACT_PHOTOS).isArray();
    LightArray<ContactField> photos = getContactFieldsForArray(photosArray);
    contact.setPhotos(photos);

    JSONArray categoriesArray = jsonContact.get(CONTACT_CATEGORIES).isArray();
    LightArray<ContactField> categories = getContactFieldsForArray(categoriesArray);
    contact.setCategories(categories);

    JSONArray urlsArray = jsonContact.get(CONTACT_URLS).isArray();
    LightArray<ContactField> urls = getContactFieldsForArray(urlsArray);
    contact.setUrls(urls);

    ContactName name = getName(jsonContact.get(CONTACT_NAME).isObject());
    contact.setName(name);

    LightArray<ContactAddress> addresses = getAddressArray(jsonContact.get(CONTACT_ADDRESSES).isArray());
    contact.setContactAddresses(addresses);

    LightArray<ContactOrganisation> organisations = getContactOrganisationArray(
            jsonContact.get(CONTACT_ORGANISATION).isArray());
    contact.setOrganisations(organisations);

    return contact;
}

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

License:Apache License

@Override
protected Date deserializeJson(JSONValue o) {
    return new Date((long) o.isNumber().doubleValue());
}

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

License:Apache License

@Override
protected Double deserializeJson(JSONValue o) {
    return o.isNumber().doubleValue();
}

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

License:Apache License

@Override
protected Float deserializeJson(JSONValue o) {
    return (float) o.isNumber().doubleValue();
}

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

License:Apache License

@Override
protected Integer deserializeJson(JSONValue o) {
    return (int) o.isNumber().doubleValue();
}

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

License:Apache License

@Override
protected Long deserializeJson(JSONValue o) {
    return (long) o.isNumber().doubleValue();
}

From source file:com.hiramchirino.restygwt.client.AbstractJsonEncoderDecoder.java

License:Apache License

static public double toDouble(JSONValue value) {
    JSONNumber number = value.isNumber();
    if (number == null) {
        throw new DecodingException("Expected a json number, but was given: " + value);
    }/*from  w ww  .  j  av  a2s.  co m*/
    return number.doubleValue();
}