List of usage examples for com.google.gwt.json.client JSONNumber JSONNumber
public JSONNumber(double value)
From source file:com.google.gson.JsonPrimitive.java
License:Apache License
/** * Create a primitive containing a {@link Number}. * * @param number the value to create the primitive with. *//* w w w . j a v a 2s. co m*/ public JsonPrimitive(Number number) { this.value = new JSONNumber(number.doubleValue()); }
From source file:com.google.gson.JsonPrimitive.java
License:Apache License
void setValue(Object primitive) { if (primitive instanceof String) { this.value = new JSONString((String) primitive); } else if (primitive instanceof Character) { // convert characters to strings since in JSON, characters are represented as a single // character string char c = ((Character) primitive).charValue(); this.value = new JSONString(String.valueOf(c)); } else if (primitive instanceof Number) { this.value = new JSONNumber(((Number) primitive).doubleValue()); } else if (primitive instanceof Boolean) { this.value = JSONBoolean.getInstance((Boolean) primitive); } else {//from ww w . j a va 2 s. c om throw new IllegalArgumentException(primitive.getClass().getName()); } }
From source file:com.googlecode.gwtphonegap.client.contacts.browser.ContactBrowserImpl.java
License:Apache License
public JSONObject serializeContact() { JSONObject root = new JSONObject(); // simple values root.put(FIELD_ID, getAsJSONString(this.getId())); root.put(CONTACT_DISPLAY_NAME, getAsJSONString(this.getDisplayName())); root.put(CONTACT_NICK_NAME, getAsJSONString(this.getNickName())); if (this.getBirthDay() != null) { double value = this.getBirthDay().getTime(); root.put(CONTACT_BIRTHDAY, new JSONNumber(value)); }/*w ww . j av a2s . co m*/ root.put(CONTACT_PHONE_NUMBERS, toJSONArray(this.getPhoneNumbers())); root.put(CONTACT_EMAILS, toJSONArray(this.getEmails())); root.put(CONTACT_IMS, toJSONArray(this.getIms())); root.put(CONTACT_PHOTOS, toJSONArray(this.getPhotos())); root.put(CONTACT_CATEGORIES, toJSONArray(this.getCategories())); root.put(CONTACT_URLS, toJSONArray(this.getUrls())); root.put(CONTACT_NAME, createContact(this.getName())); root.put(CONTACT_ADDRESSES, createAddresses(this.getContactAddresses())); root.put(CONTACT_ORGANISATION, createOrganisation(this.getOrganisations())); return root; }
From source file:com.guit.client.jsorm.DateSerializer.java
License:Apache License
@Override protected JSONValue serializeJson(Date data) { return new JSONNumber(data.getTime()); }
From source file:com.guit.client.jsorm.DoubleSerializer.java
License:Apache License
@Override protected JSONValue serializeJson(Double data) { return new JSONNumber(data); }
From source file:com.guit.client.jsorm.FloatSerializer.java
License:Apache License
@Override protected JSONValue serializeJson(Float data) { return new JSONNumber(data); }
From source file:com.guit.client.jsorm.IntegerSerializer.java
License:Apache License
@Override protected JSONValue serializeJson(Integer data) { return new JSONNumber(data); }
From source file:com.guit.client.jsorm.LongSerializer.java
License:Apache License
@Override protected JSONValue serializeJson(Long data) { return new JSONNumber(data); }
From source file:com.gwtmodel.table.json.CreateJSonForIVData.java
License:Apache License
private JSONObject toS(IVModelData v) { JSONObject j = new JSONObject(); for (IVField f : v.getF()) { JSONValue va;//from w ww . j a v a 2 s . com Object vval = FUtils.getValue(v, f); String sval = FUtils.getValueOS(vval, f); if (vval == null) va = JSONNull.getInstance(); else { switch (f.getType().getType()) { case BIGDECIMAL: BigDecimal bb = (BigDecimal) vval; va = new JSONNumber(bb.doubleValue()); break; case LONG: Long ll = (Long) vval; va = new JSONNumber(ll); break; case INT: Integer ii = (Integer) vval; va = new JSONNumber(ii); break; case BOOLEAN: Boolean bo = (Boolean) vval; va = JSONBoolean.getInstance(bo); break; default: // String ss = (String) vval; va = new JSONString(sval); break; } } String name = f.getId(); j.put(name, va); } return j; }
From source file:com.himamis.retex.renderer.web.JlmLib.java
License:Open Source License
private static JavaScriptObject createReturnValue(TeXIcon icon) { JSONObject object = new JSONObject(); object.put("width", new JSONNumber(icon.getIconWidth())); object.put("height", new JSONNumber(icon.getIconHeight())); object.put("baseline", new JSONNumber(icon.getBaseLine())); return object.getJavaScriptObject(); }