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); } 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())); } } return list; }
@Override public JSONValue encode(Object value) throws JsonEncoderDecoder.EncodingException { if (value instanceof Number) { return new JSONNumber(((Number) value).doubleValue()); } else if (value instanceof Boolean) { return JSONBoolean.getInstance((Boolean) value); } else if (value instanceof Iterable) { JSONArray array = new JSONArray(); int ct = 0; for (Object v : (Iterable<?>) value) { array.set(ct++, encode(v)); } return array; } else if (value instanceof Map) { JSONObject object = new JSONObject(); for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) { object.put(entry.getKey().toString(), encode(entry.getValue())); } return object; } else if (value == null) { return JSONNull.getInstance(); } else { return new JSONString(value.toString()); } }
private JSONValue toJSONArray(LightArray<ContactField> contactField) { JSONArray jsonArray = new JSONArray(); for (int i = 0; i < contactField.length(); i++) { ContactField field = contactField.get(i); JSONObject jsonField = new JSONObject(); jsonField.put(CONTACT_FIELD_TYPE, getAsJSONString(field.getType())); jsonField.put(CONTACT_FIELD_VALUE, getAsJSONString(field.getValue())); jsonField.put(CONTACT_FIELD_PREF, JSONBoolean.getInstance(field.isPref())); jsonArray.set(i, jsonField); } return jsonArray; }
public JSONValue toJsonElement() { JSONObject result = new JSONObject(); JSONValue packVal = JSONBoolean.getInstance(isPack());; result.put("pack", packVal); if (getUri() == null) { setUri((java.lang.String)null); } else { JSONValue uriVal = getUri() == null ? JSONNull.getInstance() : new JSONString(getUri());; result.put("uri", uriVal); } return result; }
public static FileStructureCommandParametersDto fromJson(JSONValue jsonVal) { if (jsonVal == null) { return null; } JSONObject json= jsonVal.isObject(); FileStructureCommandParametersDto result= new FileStructureCommandParametersDto(); JSONValue jsonshowInheritedJson = json.get("showInherited"); if (jsonshowInheritedJson != null && !(jsonshowInheritedJson.isNull() != null)) { boolean jsonshowInheritedVal = jsonshowInheritedJson.isBoolean().booleanValue(); result.setShowInherited((boolean)jsonshowInheritedVal); } JSONValue jsonuriJson = json.get("uri"); if (jsonuriJson != null && !(jsonuriJson.isNull() != null)) { java.lang.String jsonuriVal = jsonuriJson.isString().stringValue();; result.setUri((java.lang.String)jsonuriVal); } return result; } }
@Override public Object decode(JSONValue value) throws JsonEncoderDecoder.DecodingException { if (value instanceof JSONNumber) { return ((JSONNumber) value).doubleValue(); } else if (value instanceof JSONBoolean) { return ((JSONBoolean) value).booleanValue(); } else if (value instanceof JSONString) { return ((JSONString) value).stringValue(); } else if (value instanceof JSONArray) { JSONArray array = value.isArray(); List<Object> list = new ArrayList<Object>(array.size()); for (int ct = 0; ct < array.size(); ct++) { list.add(decode(array.get(ct))); } return list; } else if (value instanceof JSONObject) { JSONObject object = value.isObject(); Map<String, Object> map = new HashMap<String, Object>(); for (String key : object.keySet()) { map.put(key, decode(object.get(key))); } return map; } else { return null; } }
return null; JSONObject json= jsonVal.isObject(); MoveSettingsDto result= new MoveSettingsDto(); JSONValue jsondestinationJson = json.get("destination"); if (jsondestinationJson != null && !(jsondestinationJson.isNull() != null)) { java.lang.String jsondestinationVal = jsondestinationJson.isString().stringValue();; result.setDestination((java.lang.String)jsondestinationVal); JSONValue jsonupdateReferencesJson = json.get("updateReferences"); if (jsonupdateReferencesJson != null && !(jsonupdateReferencesJson.isNull() != null)) { boolean jsonupdateReferencesVal = jsonupdateReferencesJson.isBoolean().booleanValue(); result.setUpdateReferences((boolean)jsonupdateReferencesVal); JSONValue jsonupdateQualifiedNamesJson = json.get("updateQualifiedNames"); if (jsonupdateQualifiedNamesJson != null && !(jsonupdateQualifiedNamesJson.isNull() != null)) { boolean jsonupdateQualifiedNamesVal = jsonupdateQualifiedNamesJson.isBoolean().booleanValue(); result.setUpdateQualifiedNames((boolean)jsonupdateQualifiedNamesVal); JSONValue jsonfilePatternsJson = json.get("filePatterns"); if (jsonfilePatternsJson != null && !(jsonfilePatternsJson.isNull() != null)) { java.lang.String jsonfilePatternsVal = jsonfilePatternsJson.isString().stringValue();; result.setFilePatterns((java.lang.String)jsonfilePatternsVal);
@Override public Picture create(final JSONObject node, final ValidationContext ctx) throws ValidationException { final Picture picture = new Picture(node, ctx); JSONValue jval = node.get("filter"); if (null != jval) { final JSONObject object = jval.isObject(); if (null != object) { JSONDeserializer.get().deserializeFilters(picture, object, ctx); jval = object.get("active"); final JSONBoolean active = jval.isBoolean(); if (null != active) { picture.setFiltersActive(active.booleanValue()); } } } return picture; }
/** * Decodes a JSONObject to a map. * * @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.isString() != null) { map.put(key, decodeValue(j.isString().stringValue())); } } return map; }
private static ColumnView parseColumn(int rowsCount, JSONObject jsonColumn) { String storage = jsonColumn.get("storage").isString().stringValue(); String typeName = jsonColumn.get("type").isString().stringValue(); ColumnType type = ColumnType.valueOf(typeName); return new ColumnArrayView(type, jsonColumn.get("values").isArray().getJavaScriptObject()); case "empty": return new EmptyColumnView(type, rowsCount); return new ConstantColumnView(rowsCount, null); } else { return new ConstantColumnView(rowsCount, jsonString.stringValue()); return new ConstantColumnView(rowsCount, Double.NaN); } else { return new ConstantColumnView(rowsCount, jsonNumber.doubleValue()); return ConstantColumnView.nullBoolean(rowsCount); } else { return new ConstantColumnView(rowsCount, jsonValue.isBoolean().booleanValue());
@Override public String deserialize(final JSONValue jsonValue) { if (jsonValue == null || jsonValue.isNull() != null) { return null; } final JSONString jsonString = jsonValue.isString(); if (jsonString != null) { return jsonString.stringValue(); } final JSONNumber jsonNumber = jsonValue.isNumber(); if (jsonNumber != null) { return Double.toString(jsonNumber.doubleValue()); } final JSONBoolean jsonBoolean = jsonValue.isBoolean(); if (jsonBoolean != null) { return Boolean.toString(jsonBoolean.booleanValue()); } throw new GWTPojoSerializerException("Unable to deserialize " + jsonValue.toString() + " as String"); } }
@Override public Boolean deserialize(final JSONValue jsonValue) { if (jsonValue == null || jsonValue.isNull() != null) { return null; } final JSONBoolean jsonBoolean = jsonValue.isBoolean(); if (jsonBoolean != null) { return jsonBoolean.booleanValue(); } final JSONString jsonString = jsonValue.isString(); if (jsonString != null) { if (jsonString.stringValue().isEmpty()) { return null; } return Boolean.valueOf(jsonString.stringValue()); } throw new GWTPojoSerializerException("Unable to deserialize " + jsonValue.toString() + " as Boolean"); } }
return JSONNull.getInstance(); return new JSONString(value.toString()); return JSONBoolean.getInstance((Boolean) value); return new JSONNumber(((Number) value).doubleValue()); return new JSONString(((Enum<?>) value).name()); return new JSONString(String.valueOf(((Date) value).getTime()));
public static Boolean getBoolean(JSONObject json, String field) { JSONValue jsonValue; JSONBoolean jsonBoolean; if ((jsonValue = json.get(field)) == null) { return null; } if ((jsonBoolean = jsonValue.isBoolean()) == null) { return null; } return jsonBoolean.booleanValue(); }
@SuppressWarnings("unchecked") protected static JSONArray encodeList(List<Object> data) { JSONArray jsona = new JSONArray(); for (int i = 0; i < data.size(); i++) { Object val = data.get(i); if (val instanceof ModelData) { jsona.set(i, encodeMap(((ModelData) val).getProperties())); } else if (val instanceof Map) { jsona.set(i, encodeMap((Map<String, Object>) val)); } else if (val instanceof List) { jsona.set(i, encodeList((List<Object>) val)); } else if (val instanceof String) { jsona.set(i, new JSONString(encodeValue(val))); } else if (val instanceof Number) { jsona.set(i, new JSONString(encodeValue(val))); } else if (val instanceof Boolean) { jsona.set(i, JSONBoolean.getInstance((Boolean) val)); } else if (val == null) { jsona.set(i, JSONNull.getInstance()); } else if (val instanceof Date) { jsona.set(i, new JSONString(encodeValue(val))); } } return jsona; } }
/** * Creates one of implementations of {@link EditorPropertyWidget}. * * @return an instance of {@link EditorPropertyWidget} */ public EditorPropertyWidget create(@NotNull String propertyName, @NotNull JSONValue value) { if (value.isBoolean() != null) { return new EditorBooleanPropertyWidget(propertyName, value.isBoolean().booleanValue()); } if (value.isNumber() != null) { Double doubleValue = value.isNumber().doubleValue(); return new EditorNumberPropertyWidget(propertyName, doubleValue.intValue()); } return new EditorStringPropertyWidget(propertyName, value.toString()); } }
public static <Type> JSONValue toJSON(boolean[] value, AbstractJsonEncoderDecoder<Type> encoder) { if (value == null) { return getNullType(); } JSONArray rc = new JSONArray(); int i = 0; for (boolean t : value) { rc.set(i++, JSONBoolean.getInstance(t)); } return rc; }
public JSON append(final String propName, final boolean value) { object.put(propName, JSONBoolean.getInstance(value)); return this; }
@Override public Boolean decode(JSONValue value) throws DecodingException { if (value == null || value.isNull() != null) { return null; } JSONBoolean bool = value.isBoolean(); if (bool == null) { throw new DecodingException("Expected a json boolean, but was given: " + value); } return bool.booleanValue(); }
defaultPreferences.put(TAB_SIZE.toString(), new JSONNumber(4)); defaultPreferences.put(EXPAND_TAB.toString(), JSONBoolean.getInstance(true)); defaultPreferences.put(ENABLE_AUTO_SAVE.toString(), JSONBoolean.getInstance(true)); defaultPreferences.put(SOFT_WRAP.toString(), JSONBoolean.getInstance(false)); defaultPreferences.put(AUTO_PAIR_PARENTHESES.toString(), JSONBoolean.getInstance(true)); defaultPreferences.put(AUTO_PAIR_BRACES.toString(), JSONBoolean.getInstance(true)); defaultPreferences.put(AUTO_PAIR_SQUARE_BRACKETS.toString(), JSONBoolean.getInstance(true)); defaultPreferences.put(AUTO_PAIR_ANGLE_BRACKETS.toString(), JSONBoolean.getInstance(true)); defaultPreferences.put(AUTO_PAIR_QUOTATIONS.toString(), JSONBoolean.getInstance(true)); defaultPreferences.put(AUTO_COMPLETE_COMMENTS.toString(), JSONBoolean.getInstance(true)); defaultPreferences.put(SMART_INDENTATION.toString(), JSONBoolean.getInstance(true)); defaultPreferences.put(SHOW_WHITESPACES.toString(), JSONBoolean.getInstance(false)); defaultPreferences.put(SHOW_ANNOTATION_RULER.toString(), JSONBoolean.getInstance(true)); defaultPreferences.put(SHOW_LINE_NUMBER_RULER.toString(), JSONBoolean.getInstance(true)); defaultPreferences.put(SHOW_FOLDING_RULER.toString(), JSONBoolean.getInstance(true)); defaultPreferences.put(SHOW_OVERVIEW_RULER.toString(), JSONBoolean.getInstance(true)); defaultPreferences.put(SHOW_ZOOM_RULER.toString(), JSONBoolean.getInstance(true)); defaultPreferences.put(SHOW_OCCURRENCES.toString(), JSONBoolean.getInstance(true)); defaultPreferences.put( SHOW_CONTENT_ASSIST_AUTOMATICALLY.toString(), JSONBoolean.getInstance(true));