List of usage examples for com.google.gwt.json.client JSONNumber JSONNumber
public JSONNumber(double value)
From source file:com.stoyanr.todo.client.presenter.JsonSerializer.java
License:Open Source License
public JSONObject toJson(Document document) { JSONObject result = new JSONObject(); result.put(USER_ID, new JSONString(document.getUserId())); result.put(LAST_SAVED, new JSONNumber(document.getLastSaved().getTime())); return result; }
From source file:com.symantec.gwt.flot.client.Flot.java
License:Open Source License
protected JavaScriptObject getOptionsAsJson() { JSONObject obj = new JSONObject(); obj.put("color", new JSONNumber(1)); obj.put("series", seriesOptions.asJson()); obj.put("shadowSize", new JSONNumber(0)); obj.put("borderWidth", new JSONNumber(1)); obj.put("borderColor", new JSONString("#DDDDDD")); if (legend != null) { obj.put("legend", legend.asJson()); }/*from w w w.j a va 2s.co m*/ obj.put("grid", getGridOptionsAsJson()); obj.put("font", getFontOptions()); if (seriesOptions instanceof LineSeriesOptions) { LineSeriesOptions opt = (LineSeriesOptions) seriesOptions; obj.put("markings", opt.getMarkingsConfig()); } JSONObject otherOptions = getOptions(); if (otherOptions != null) { for (String key : otherOptions.keySet()) { obj.put(key, otherOptions.get(key)); } } return obj.getJavaScriptObject(); }
From source file:com.symantec.gwt.flot.client.Flot.java
License:Open Source License
private JSONValue getFontOptions() { JSONObject fontOpts = new JSONObject(); fontOpts.put("size", new JSONNumber(11)); fontOpts.put("style", new JSONString("normal")); fontOpts.put("weight", new JSONString("normal")); fontOpts.put("family", new JSONString("Tahoma")); return fontOpts; }
From source file:com.thesarvo.guide.client.raphael.Attr.java
License:Apache License
public Attr width(double width) { this.put("width", new JSONNumber(width)); return this; }
From source file:com.vaadin.client.communication.Date_Serializer.java
License:Apache License
@Override public JSONValue serialize(Date value, ApplicationConnection connection) { return new JSONNumber(value.getTime()); }
From source file:com.vaadin.client.communication.JsonEncoder.java
License:Apache License
/** * Encode a value to a JSON representation for transport from the client to * the server.//from w ww . ja v a2s .c om * * @param value * value to convert * @param connection * @return JSON representation of the value */ public static JSONValue encode(Object value, Type type, ApplicationConnection connection) { if (null == value) { return JSONNull.getInstance(); } else if (value instanceof JSONValue) { return (JSONValue) value; } else if (value instanceof String[]) { String[] array = (String[]) value; JSONArray jsonArray = new JSONArray(); for (int i = 0; i < array.length; ++i) { jsonArray.set(i, new JSONString(array[i])); } return jsonArray; } else if (value instanceof String) { return new JSONString((String) value); } else if (value instanceof Boolean) { return JSONBoolean.getInstance((Boolean) value); } else if (value instanceof Byte) { return new JSONNumber((Byte) value); } else if (value instanceof Character) { return new JSONString(String.valueOf(value)); } else if (value instanceof Object[] && type == null) { // Non-legacy arrays handed by generated serializer return encodeLegacyObjectArray((Object[]) value, connection); } else if (value instanceof Enum) { return encodeEnum((Enum<?>) value, connection); } else if (value instanceof Map) { return encodeMap((Map) value, type, connection); } else if (value instanceof Connector) { Connector connector = (Connector) value; return new JSONString(connector.getConnectorId()); } else if (value instanceof Collection) { return encodeCollection((Collection) value, type, connection); } else if (value instanceof UidlValue) { return encodeVariableChange((UidlValue) value, connection); } else { // First see if there's a custom serializer JSONSerializer<Object> serializer = null; if (type != null) { serializer = (JSONSerializer<Object>) type.findSerializer(); if (serializer != null) { return serializer.serialize(value, connection); } } String transportType = getTransportType(value); if (transportType != null) { // Send the string value for remaining legacy types return new JSONString(String.valueOf(value)); } else if (type != null) { // And finally try using bean serialization logic try { JsArrayObject<Property> properties = type.getPropertiesAsArray(); JSONObject jsonObject = new JSONObject(); int size = properties.size(); for (int i = 0; i < size; i++) { Property property = properties.get(i); Object propertyValue = property.getValue(value); Type propertyType = property.getType(); JSONValue encodedPropertyValue = encode(propertyValue, propertyType, connection); jsonObject.put(property.getName(), encodedPropertyValue); } return jsonObject; } catch (NoDataException e) { throw new RuntimeException("Can not encode " + type.getSignature(), e); } } else { throw new RuntimeException("Can't encode " + value.getClass() + " without type information"); } } }
From source file:cometedgwt.auction.client.App.java
License:Open Source License
private void sendNewBid(AuctionItem item, TextBox myBid, Label message) { int itemId = item.getId(); double lastBid = item.getPrice(); String newBid = myBid.getText(); double newBidValue = 0.0; try {/*from w w w . ja v a 2 s. c om*/ newBidValue = Double.parseDouble(newBid); } catch (NumberFormatException e) { message.setText("Not a valid bid"); return; } if (newBidValue < lastBid) { message.setText("Not a valid bid"); return; } message.setText(""); item.setPrice(newBidValue); int numberOfBids = item.getNumberOfBids(); JSONArray array = new JSONArray(); array.set(0, new JSONNumber(itemId)); array.set(1, new JSONNumber(newBidValue)); array.set(2, new JSONNumber(numberOfBids)); JSONObject container = new JSONObject(); container.put("value", array); streamingService.sendMessage(TOPIC, container); myBid.setText(""); myBid.setFocus(true); }
From source file:core.util.JSON_.java
License:GNU General Public License
public static Object newNumber(long v) { return new JSONNumber(v); }
From source file:de.catma.ui.client.ui.tagger.ClientTagInstanceJSONSerializer.java
License:Open Source License
public String toJSONObject(ClientTagInstance tagInstance) { JSONObject tagInstanceJSON = new JSONObject(); tagInstanceJSON.put(SerializationField.tagDefinitionID.name(), new JSONString(tagInstance.getTagDefinitionID())); tagInstanceJSON.put(SerializationField.instanceID.name(), new JSONString(tagInstance.getInstanceID())); tagInstanceJSON.put(SerializationField.color.name(), new JSONString(tagInstance.getColor())); JSONArray rangesJSON = new JSONArray(); int i = 0;/*from w w w .j a v a 2 s. com*/ for (TextRange tr : tagInstance.getRanges()) { JSONObject trJSON = new JSONObject(); trJSON.put(SerializationField.startPos.name(), new JSONNumber(tr.getStartPos())); trJSON.put(SerializationField.endPos.name(), new JSONNumber(tr.getEndPos())); rangesJSON.set(i, trJSON); i++; } tagInstanceJSON.put(SerializationField.ranges.name(), rangesJSON); return tagInstanceJSON.toString(); }
From source file:edu.nrao.dss.client.PeriodJSON.java
License:Open Source License
private void initTimeAccounting() { String[] fields = { "lost_time", "lost_time_other", "lost_time_rfi", "lost_time_weather", "other_session", "other_session_other", "other_session_rfi", "other_session_weather", "scheduled", "short_notice", "not_billable", "unaccounted_time", "lost_time_bill_project", "time_billed", "observed" }; for (int i = 0; i < fields.length; i++) { this.put(fields[i], new JSONNumber(0.0)); }/* w w w . j av a 2 s . c o m*/ }