@Override public JSONValue serialize(final String value) { if (value == null) { return JSONNull.getInstance(); } return new JSONString(value); }
public JSON appendNull(final String propName) { object.put(propName, JSONNull.getInstance()); return this; }
public JSONObject toJsonObjectInt(boolean copyJsons) { JSONObject result = new JSONObject(); JSONValue stateOut = (this.state == null) ? JSONNull.getInstance() : new JSONString(this.state.name()); result.put("state", stateOut); JSONValue outputOut = (this.output == null) ? JSONNull.getInstance() : new JSONString(this.output); result.put("output", outputOut); return result; }
public JSONValue toJsonElement() { JSONObject result = new JSONObject(); if (getProjectsToUpdate() == null) { setProjectsToUpdate((java.util.List<java.lang.String>)null); } else { JSONArray projectsToUpdateVal = new JSONArray(); for (java.lang.String projectsToUpdateValX : getProjectsToUpdate()) { JSONValue projectsToUpdateValY = projectsToUpdateValX == null ? JSONNull.getInstance() : new JSONString(projectsToUpdateValX);; projectsToUpdateVal.set(projectsToUpdateVal.size(), projectsToUpdateValY); } result.put("projectsToUpdate", projectsToUpdateVal); } return result; }
@Override public JSONObject toJSONObject() { final JSONObject obj = super.toJSONObject(); final JSONArray lines = new JSONArray(); final JSONArray sizes = new JSONArray(); for (int i = 0; i < 4; i++) { if (m_lines[i] == null) { lines.set(i, JSONNull.getInstance()); } else { lines.set(i, m_lines[i].toJSONObject()); } sizes.set(i, new JSONNumber(m_sizes[i])); } obj.put("lines", lines); obj.put("sizes", sizes); return obj; }
@Override public JSONValue serialize(final boolean[] value) { if (value == null) { return JSONNull.getInstance(); } final JSONArray jsonArray = new JSONArray(); for (int i = 0; i < value.length; i++) { jsonArray.set(i, BooleanSerializer.INSTANCE.serialize(value[i])); } return jsonArray; }
public JSONValue toJsonElement() { JSONObject result = new JSONObject(); if (getRefactoringStatus() == null) { setRefactoringStatus((org.eclipse.che.jdt.ls.extension.api.dto.RefactoringStatus)null); } else { JSONValue refactoringStatusVal = getRefactoringStatus() == null ? JSONNull.getInstance() : ((RefactoringStatusDto)getRefactoringStatus()).toJsonElement();; result.put("refactoringStatus", refactoringStatusVal); } if (getCheWorkspaceEdit() == null) { setCheWorkspaceEdit((org.eclipse.che.jdt.ls.extension.api.dto.CheWorkspaceEdit)null); } else { JSONValue cheWorkspaceEditVal = getCheWorkspaceEdit() == null ? JSONNull.getInstance() : ((CheWorkspaceEditDto)getCheWorkspaceEdit()).toJsonElement();; result.put("cheWorkspaceEdit", cheWorkspaceEditVal); } return result; }
@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; } }
/** * Parse the given JSON string into a {@link JSONObject}. * * @param jsonString The trusted JSON string to parse. * @return The JSON object that results from the parsed string. * @throws JSONException Thrown in case something went wrong during parsing. */ public static JSONValue parse(String jsonString) throws JSONException { if (jsonString == null || "".equals(jsonString)) { return JSONNull.getInstance(); } if (jsonString.charAt(0) == '[') { return new JSONArray(eval(jsonString)); } return new JSONObject(eval(jsonString)); }
@Override public JSONValue serialize(final Map<K, V> map) { if (map == null) { return JSONNull.getInstance(); } final JSONObject jsonObject = new JSONObject(); for (K key : map.keySet()) { GWTPojoSerializerUtils.setProperty(jsonObject, key.toString(), vSerializer.serialize(map.get(key))); } return jsonObject; }
public JSONValue toJsonElement() { JSONObject result = new JSONObject(); if (getAddedProjectsUri() == null) { setAddedProjectsUri((java.util.List<java.lang.String>)null); } else { JSONArray addedProjectsUriVal = new JSONArray(); for (java.lang.String addedProjectsUriValX : getAddedProjectsUri()) { JSONValue addedProjectsUriValY = addedProjectsUriValX == null ? JSONNull.getInstance() : new JSONString(addedProjectsUriValX);; addedProjectsUriVal.set(addedProjectsUriVal.size(), addedProjectsUriValY); } result.put("addedProjectsUri", addedProjectsUriVal); } if (getRemovedProjectsUri() == null) { setRemovedProjectsUri((java.util.List<java.lang.String>)null); } else { JSONArray removedProjectsUriVal = new JSONArray(); for (java.lang.String removedProjectsUriValX : getRemovedProjectsUri()) { JSONValue removedProjectsUriValY = removedProjectsUriValX == null ? JSONNull.getInstance() : new JSONString(removedProjectsUriValX);; removedProjectsUriVal.set(removedProjectsUriVal.size(), removedProjectsUriValY); } result.put("removedProjectsUri", removedProjectsUriVal); } return result; }
public JSONObject toJsonObjectInt(boolean copyJsons) { JSONObject result = new JSONObject(); JSONObject schemasOut = new JSONObject(); this.ensureSchemas(); for (java.util.Map.Entry<String, java.lang.String> entry0 : this.schemas.entrySet()) { java.lang.String schemas_ = entry0.getValue(); JSONValue schemasOut_ = (schemas_ == null) ? JSONNull.getInstance() : new JSONString(schemas_); schemasOut.put(entry0.getKey(), schemasOut_); } result.put("schemas", schemasOut); return result; }
@Override public JSONObject toJSONObject() { JSONObject obj = super.toJSONObject(); JSONArray lines = new JSONArray(); JSONArray sizes = new JSONArray(); for (int i = 0; i < 4; i++) { if (m_lines[i] == null) { lines.set(i, JSONNull.getInstance()); } else { lines.set(i, m_lines[i].toJSONObject()); } sizes.set(i, new JSONNumber(m_sizes[i])); } obj.put("lines", lines); obj.put("sizes", sizes); // TODO could put sizes in Attributes return obj; }
@Override public JSONValue serialize(final float[] value) { if (value == null) { return JSONNull.getInstance(); } final JSONArray jsonArray = new JSONArray(); for (int i = 0; i < value.length; i++) { jsonArray.set(i, FloatSerializer.INSTANCE.serialize(value[i])); } return jsonArray; }
public void testReadListFromJSONObjectWithNonExistingArray() { JSONObject json = null; List<Amoeba> amoebas = null; json = new JSONObject(); json.put("foo", JSONNull.getInstance()); amoebas = Amoeba.JSON_READER.readList(json); assertNull(amoebas); json = new JSONObject(); json.put("foo", new JSONNumber(123)); amoebas = Amoeba.JSON_READER.readList(json); assertNull(amoebas); json = new JSONObject(); json.put("foo", JSONBoolean.getInstance(false)); amoebas = Amoeba.JSON_READER.readList(json); assertNull(amoebas); json = new JSONObject(); json.put("foo", new JSONObject()); amoebas = Amoeba.JSON_READER.readList(json); assertNull(amoebas); }
private static JSONValue getAsJSONString(String id) { if (id == null) { return JSONNull.getInstance(); } return new JSONString(id); }
@Override public JSONValue serialize(final Object value) { if (value == null) { return JSONNull.getInstance(); } else if (value instanceof Number) { return DoubleSerializer.INSTANCE.serialize((Number)value); } else if (value instanceof Object[]) { final Object[] objectArray = (Object[])value; final JSONArray jsonArray = new JSONArray(); for (int i = 0; i < objectArray.length; i++) { jsonArray.set(i, serialize(objectArray[i])); return new MapSerializer<String, Object>(StringSerializer.INSTANCE, this).serialize(map); return new JSONString(value.toString());
public JSON appendNull(final String propName) { object.put(propName, JSONNull.getInstance()); return this; }
@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()); } }
public JSONObject toJsonObjectInt(boolean copyJsons) { JSONObject result = new JSONObject(); JSONValue versionOut = (this.version == null) ? JSONNull.getInstance() : new JSONString(this.version); result.put("version", versionOut); JSONValue repositoryOut = (this.repository == null) ? JSONNull.getInstance() : new JSONString(this.repository); result.put("repository", repositoryOut); JSONObject propertiesOut = new JSONObject(); this.ensureProperties(); for (java.util.Map.Entry<String, java.lang.String> entry0 : this.properties.entrySet()) { java.lang.String properties_ = entry0.getValue(); JSONValue propertiesOut_ = (properties_ == null) ? JSONNull.getInstance() : new JSONString(properties_); propertiesOut.put(entry0.getKey(), propertiesOut_); } result.put("properties", propertiesOut); JSONValue artifactIdOut = (this.artifactId == null) ? JSONNull.getInstance() : new JSONString(this.artifactId); result.put("artifactId", artifactIdOut); JSONValue groupIdOut = (this.groupId == null) ? JSONNull.getInstance() : new JSONString(this.groupId); result.put("groupId", groupIdOut); return result; }