List of usage examples for org.json JSONObject NULL
Object NULL
To view the source code for org.json JSONObject NULL.
Click Source Link
NULL
object than to use Java's null
value. From source file:net.dv8tion.jda.core.managers.GuildManagerUpdatable.java
/** * Creates a new {@link net.dv8tion.jda.core.requests.RestAction RestAction} instance * that will apply <b>all</b> changes that have been made to this manager instance. * <br>If no changes have been made this will simply return {@link net.dv8tion.jda.core.requests.RestAction.EmptyRestAction EmptyRestAction}. * * <p>Before applying new changes it is recommended to call {@link #reset()} to reset previous changes. * <br>This is automatically called if this method returns successfully. * * <p>Possible {@link net.dv8tion.jda.core.requests.ErrorResponse ErrorResponses} for this * update include the following://from ww w. j a va 2 s .co m * <ul> * <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#UNKNOWN_GUILD UNKNOWN_GUILD} * <br>If the Guild was deleted before finishing the task</li> * * <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS} * <br>If the currently logged in account loses the {@link net.dv8tion.jda.core.Permission#MANAGE_SERVER MANAGE_SERVER Permission} * before finishing the task</li> * </ul> * * @throws net.dv8tion.jda.core.exceptions.PermissionException * If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_SERVER MANAGE_SERVER} * in the underlying {@link net.dv8tion.jda.core.entities.Guild Guild} * @throws net.dv8tion.jda.core.exceptions.GuildUnavailableException * If the Guild is temporarily not {@link net.dv8tion.jda.core.entities.Guild#isAvailable() available} * * @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction} * <br>Applies all changes that have been made in a single api-call. */ @CheckReturnValue public AuditableRestAction<Void> update() { checkAvailable(); checkPermission(Permission.MANAGE_SERVER); if (!needToUpdate()) return new AuditableRestAction.EmptyRestAction<>(getJDA(), null); JSONObject body = new JSONObject().put("name", guild.getName()); if (name.shouldUpdate()) body.put("name", name.getValue()); if (region.shouldUpdate()) body.put("region", region.getValue().getKey()); if (timeout.shouldUpdate()) body.put("afk_timeout", timeout.getValue().getSeconds()); if (icon.shouldUpdate()) body.put("icon", icon.getValue() == null ? JSONObject.NULL : icon.getValue().getEncoding()); if (splash.shouldUpdate()) body.put("splash", splash.getValue() == null ? JSONObject.NULL : splash.getValue().getEncoding()); if (afkChannel.shouldUpdate()) body.put("afk_channel_id", afkChannel.getValue() == null ? JSONObject.NULL : afkChannel.getValue().getId()); if (verificationLevel.shouldUpdate()) body.put("verification_level", verificationLevel.getValue().getKey()); if (defaultNotificationLevel.shouldUpdate()) body.put("default_notification_level", defaultNotificationLevel.getValue().getKey()); if (mfaLevel.shouldUpdate()) body.put("mfa_level", mfaLevel.getValue().getKey()); if (explicitContentLevel.shouldUpdate()) body.put("explicit_content_filter", explicitContentLevel.getValue().getKey()); reset(); //now that we've built our JSON object, reset the manager back to the non-modified state Route.CompiledRoute route = Route.Guilds.MODIFY_GUILD.compile(guild.getId()); return new AuditableRestAction<Void>(guild.getJDA(), route, body) { @Override protected void handleResponse(Response response, Request<Void> request) { if (response.isOk()) request.onSuccess(null); else request.onFailure(response); } }; }
From source file:com.microsoft.campaignmanager.viewmodel.CampaignListViewItem.java
/** * Safe string.// w ww. j ava 2 s. c o m * * @param object the object * @return the string */ private String safeString(Object object) { if (object == null) return ""; if (object.equals(JSONObject.NULL)) { return ""; } return object.toString().trim(); }
From source file:com.reignite.parser.QueryParser.java
/** * Handles the case where a value for a criterion needs to be converted into * a native format like a date. To create native object use format like: * !Date(string,pattern) eg: Date(12/31/2013,dd/mm/yyyy) * //from w ww . j a v a2 s .c o m * @param object * @return */ public Object createValue(Object object) throws ParserException { Object value = object; if (object instanceof String) { if (object == null || object.toString().toLowerCase().equals("null")) { return null; } String string = (String) object; if (string != null) { if (string.startsWith("!")) { string = string.substring(1); String typeString = string.substring(0, string.indexOf("(")); if (typeString.toLowerCase().equals("date")) { String dateString = string.substring(string.indexOf("(") + 1, string.indexOf(",")); String pattern = string.substring(string.indexOf(",") + 1, string.indexOf(")")); DateFormat df = new SimpleDateFormat(pattern); try { value = df.parse(dateString); } catch (ParseException e) { throw new ParserException("Failed to parse date: " + dateString + " of pattern: " + pattern + " Cause: " + e, e); } } } else if (string.startsWith("\\")) { value = string.substring(1); } } } else if (object != null && JSONObject.NULL.equals(object)) { value = null; } return value; }
From source file:org.hubiquitus.twitter4j_1_1.stream.HUserStream.java
/** * Determine if the value associated with the key is null or if there is * no value./*from w w w .j a va2s . co m*/ * * @param key A key string. * @return true if there is no value associated with the key or if * the value is the JSONObject.NULL object. */ public boolean isNull(String key) { return JSONObject.NULL.equals(opt(key)); }
From source file:com.ichi2.anki.dialogs.CustomStudyDialog.java
/** * Create a custom study session// ww w . j a v a 2 s . c o m * @param delays delay options for scheduling algorithm * @param terms search terms * @param resched whether to reschedule the cards based on the answers given (or ignore them if false) */ private void createCustomStudySession(JSONArray delays, Object[] terms, Boolean resched) { JSONObject dyn; final AnkiActivity activity = (AnkiActivity) getActivity(); Collection col = CollectionHelper.getInstance().getCol(activity); try { long did = getArguments().getLong("did"); String deckName = col.getDecks().get(did).getString("name"); String customStudyDeck = getResources().getString(R.string.custom_study_deck_name); JSONObject cur = col.getDecks().byName(customStudyDeck); if (cur != null) { if (cur.getInt("dyn") != 1) { new MaterialDialog.Builder(getActivity()).content(R.string.custom_study_deck_exists) .negativeText(R.string.dialog_cancel).build().show(); return; } else { // safe to empty col.getSched().emptyDyn(cur.getLong("id")); // reuse; don't delete as it may have children dyn = cur; col.getDecks().select(cur.getLong("id")); } } else { long customStudyDid = col.getDecks().newDyn(customStudyDeck); dyn = col.getDecks().get(customStudyDid); } // and then set various options if (delays.length() > 0) { dyn.put("delays", delays); } else { dyn.put("delays", JSONObject.NULL); } JSONArray ar = dyn.getJSONArray("terms"); ar.getJSONArray(0).put(0, "deck:\"" + deckName + "\" " + terms[0]); ar.getJSONArray(0).put(1, terms[1]); ar.getJSONArray(0).put(2, terms[2]); dyn.put("resched", resched); // Rebuild the filtered deck DeckTask.launchDeckTask(DeckTask.TASK_TYPE_REBUILD_CRAM, new DeckTask.TaskListener() { @Override public void onCancelled() { } @Override public void onPreExecute() { activity.showProgressBar(); } @Override public void onPostExecute(DeckTask.TaskData result) { activity.hideProgressBar(); ((CustomStudyListener) activity).onCreateCustomStudySession(); } @Override public void onProgressUpdate(DeckTask.TaskData... values) { } }); } catch (JSONException e) { throw new RuntimeException(e); } // Hide the dialogs activity.dismissAllDialogFragments(); }
From source file:net.markenwerk.utils.structurers.json.JsonDescendListener.java
@Override public void onNull() { adders.peek().onResult(JSONObject.NULL); }
From source file:com.evolveum.polygon.test.scim.StandardScimTestUtils.java
protected static JSONObject userToConnIdSimulation(Integer testNumber) { JSONObject testJson = new JSONObject(); StringBuilder buildUpdateEmailAdress = new StringBuilder(testNumber.toString()) .append("testupdateuser@testdomain.com"); JSONObject nameObject = new JSONObject(); nameObject.put("givenName", JSONObject.NULL); nameObject.put("familyName", JSONObject.NULL); JSONArray emailArray = new JSONArray(); JSONObject emailObject = new JSONObject(); emailObject.put("value", buildUpdateEmailAdress.toString()); emailObject.put("primary", true); emailArray.put(emailObject);// w w w .java2 s . c om testJson.put("displayName", ""); testJson.put("active", true); testJson.put("userName", buildUpdateEmailAdress.toString()); testJson.put("nickName", testNumber.toString()); testJson.put("emails", emailArray); testJson.put("name", nameObject); testJson.put("id", "123456789"); return testJson; }
From source file:com.azirar.requester.ws.utils.RequesterUtils.java
private JSONObject buildJson(Request request, Result result, Row row) throws RequesterException { JSONObject jsonObject = new JSONObject(); Service service = getService(request.getIdService(), request.getIdConfiguration()); Configuration configuration = getConfiguration(request.getIdConfiguration()); if (service.isGetOperation()) for (ItemValue item : row.getItemValues()) { String translatedName = configuration.translate(request.getLanguage().trim(), item.getName()); if (item.getValue() != null) { Column vColumn = getColumnByName(item.getName(), request.getIdService(), request.getIdConfiguration()); if (vColumn.isText()) { jsonObject.put(translatedName, item.getValue()); }// w ww. ja v a 2s . c o m if (vColumn.isNumber() || vColumn.isDate()) { jsonObject.put(translatedName, Long.parseLong(item.getValue())); } if (vColumn.isFoat()) { jsonObject.put(translatedName, Long.parseLong(item.getValue())); } if (vColumn.isBoolean()) { jsonObject.put(translatedName, Boolean.parseBoolean(item.getValue())); } } else { jsonObject.put(translatedName, JSONObject.NULL); } } else jsonObject.put(row.getItemValues().get(0).getName(), row.getItemValues().get(0).getValue()); return jsonObject; }
From source file:com.telefonica.euro_iaas.paasmanager.model.RouterInstance.java
/** * Constructor from a json message./*from w w w. ja v a 2 s. c o m*/ * @param jsonRouter The json message. * @return * @throws JSONException */ public static RouterInstance fromJson(JSONObject jsonRouter) throws JSONException { String name = (String) jsonRouter.get("name"); String id = (String) jsonRouter.get("id"); boolean adminStateUp = (Boolean) jsonRouter.get("admin_state_up"); String tenantId = (String) jsonRouter.get("tenant_id"); String networkId = ""; try { JSONObject array = jsonRouter.getJSONObject("external_gateway_info"); networkId = (String) array.get("network_id"); } catch (Exception e) { if (!(jsonRouter.get("external_gateway_info") == JSONObject.NULL)) { networkId = (String) jsonRouter.get("external_gateway_info"); } } RouterInstance router = new RouterInstance(); router.setIdRouter(id); router.setTenantId(tenantId); router.setAdminStateUp(adminStateUp); router.setNetworkId(networkId); router.setName(name); return router; }
From source file:com.facebook.stetho.json.ObjectMapper.java
private Object getValueForField(Field field, Object value) throws JSONException { try {//from w ww . j a va 2 s. c o m if (value != null) { if (value == JSONObject.NULL) { return null; } if (value.getClass() == field.getType()) { return value; } if (value instanceof JSONObject) { return convertValue(value, field.getType()); } else { if (field.getType().isEnum()) { return getEnumValue((String) value, field.getType().asSubclass(Enum.class)); } else if (value instanceof JSONArray) { return convertArrayToList(field, (JSONArray) value); } else if (value instanceof Number) { // Need to convert value to Number This happens because json treats 1 as an Integer even // if the field is supposed to be a Long Number numberValue = (Number) value; Class<?> clazz = field.getType(); if (clazz == Integer.class || clazz == int.class) { return numberValue.intValue(); } else if (clazz == Long.class || clazz == long.class) { return numberValue.longValue(); } else if (clazz == Double.class || clazz == double.class) { return numberValue.doubleValue(); } else if (clazz == Float.class || clazz == float.class) { return numberValue.floatValue(); } else if (clazz == Byte.class || clazz == byte.class) { return numberValue.byteValue(); } else if (clazz == Short.class || clazz == short.class) { return numberValue.shortValue(); } else { throw new IllegalArgumentException("Not setup to handle class " + clazz.getName()); } } } } } catch (IllegalAccessException e) { throw new IllegalArgumentException("Unable to set value for field " + field.getName(), e); } return value; }