com.atlassian.jira.util.json.JSONObject.put()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(155)

本文整理了Java中com.atlassian.jira.util.json.JSONObject.put()方法的一些代码示例,展示了JSONObject.put()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.put()方法的具体详情如下:
包路径:com.atlassian.jira.util.json.JSONObject
类名称:JSONObject
方法名:put

JSONObject.put介绍

[英]Put a key/double pair in the JSONObject.
[中]在JSONObject中放置一个密钥/双精度对。

代码示例

代码示例来源:origin: com.atlassian.jira/jira-api

/**
 * Put a key/boolean pair in the JSONObject.
 *
 * @param key   A key string.
 * @param value A boolean which is the value.
 * @return this.
 * @throws JSONException If the key is null.
 */
public JSONObject put(final String key, final boolean value) throws JSONException
{
  put(key, value ? Boolean.TRUE : Boolean.FALSE);
  return this;
}

代码示例来源:origin: com.atlassian.jira/jira-api

/**
 * Put a key/value pair in the JSONObject, but only if the
 * key and the value are both non-null.
 *
 * @param key   A key string.
 * @param value An object which is the value. It should be of one of these
 *              types: Boolean, Double, Integer, JSONArray, JSONObject, Long, String,
 *              or the JSONObject.NULL object.
 * @return this.
 * @throws JSONException If the value is a non-finite number.
 */
public JSONObject putOpt(final String key, final Object value) throws JSONException
{
  if ((key != null) && (value != null))
  {
    put(key, value);
  }
  return this;
}

代码示例来源:origin: com.atlassian.jira/jira-api

/**
 * Put a key/int pair in the JSONObject.
 *
 * @param key   A key string.
 * @param value An int which is the value.
 * @return this.
 * @throws JSONException If the key is null.
 */
public JSONObject put(final String key, final int value) throws JSONException
{
  put(key, new Integer(value));
  return this;
}

代码示例来源:origin: com.atlassian.jira/jira-api

/**
 * Put a key/double pair in the JSONObject.
 *
 * @param key   A key string.
 * @param value A double which is the value.
 * @return this.
 * @throws JSONException If the key is null or if the number is invalid.
 */
public JSONObject put(final String key, final double value) throws JSONException
{
  put(key, new Double(value));
  return this;
}

代码示例来源:origin: com.atlassian.jira/jira-api

/**
 * Put a key/long pair in the JSONObject.
 *
 * @param key   A key string.
 * @param value A long which is the value.
 * @return this.
 * @throws JSONException If the key is null.
 */
public JSONObject put(final String key, final long value) throws JSONException
{
  put(key, new Long(value));
  return this;
}

代码示例来源:origin: com.atlassian.jira/jira-core

private static JSONObject toJson(String avatarUrl, String fullName, String email, String username)
{
  JSONObject result = new JSONObject();
  try
  {
    result.put("avatarUrl", avatarUrl)
        .put("displayName", fullName)
        .put("emailAddress", email)
        .put("username", username);
  } 
  catch (JSONException e)
  {
    log.info("It has failed to create an Json object for given information, so that the empty Json will be returned", e);
  }
  finally
  {
    return result;
  }
}

代码示例来源:origin: com.atlassian.plugin.automation/jira-automation-spi

public String getJSONString()
{
  try
  {
    return new JSONObject().put(LAST_KEY, last).put(ALL_KEY, all).toString();
  }
  catch (JSONException e)
  {
    return "{}";
  }
}

代码示例来源:origin: com.atlassian.plugin.automation/jira-automation-spi

private static JSONObject createJSONEntry(DateTime when, String entry)
  {
    try
    {
      return new JSONObject().put("date", when.toString(ISO_DATE_FORMAT)).put("entry", entry);
    }
    catch (JSONException e)
    {
      return new JSONObject();
    }
  }
}

代码示例来源:origin: com.atlassian.jira/jira-api

/**
 * Put a key/value pair in the JSONObject, where the value will be a
 * JSONObject which is produced from a Map.
 *
 * @param key   A key string.
 * @param value A Map value.
 * @return this.
 * @throws JSONException If the value is non-finite number or if the key is null.
 */
public JSONObject put(final String key, final Map<String, Object> value) throws JSONException
{
  put(key, new JSONObject(value));
  return this;
}

代码示例来源:origin: com.atlassian.jira/jira-api

/**
 * Put a key/value pair in the JSONObject, where the value will be a
 * JSONArray which is produced from a Collection.
 *
 * @param key   A key string.
 * @param values A Collection value.
 * @return this.
 * @throws JSONException If the value is non-finite number or if the key is null.
 */
public JSONObject put(final String key, final Collection<Object> values) throws JSONException
{
  put(key, new JSONArray(values));
  return this;
}

代码示例来源:origin: com.atlassian.jira/jira-core

@Override
  public JSONObject apply(final AttachmentArchiveEntry entry)
  {
    try
    {
      final JSONObject json = new JSONObject();
      json.put("entryIndex", entry.getEntryIndex());
      json.put("name", entry.getName());
      json.put("size", entry.getSize());
      json.put("mediaType", entry.getMediaType());
      return json;
    }
    catch (final JSONException e)
    {
      throw new RuntimeException(e);
    }
  }
}

代码示例来源:origin: com.atlassian.jira/jira-core

private String getLanguageTextsJsonForLocale(final Locale locale) throws JSONException
{
  final I18nHelper i18nHelper = ComponentAccessor.getI18nHelperFactory().getInstance(locale);
  final JSONObject json = new JSONObject();
  json.put("button", i18nHelper.getText("common.words.save"));
  json.put("cancel", i18nHelper.getText("common.forms.cancel"));
  json.put("connectionWarningContent", i18nHelper.getText("setup.language.dialog.connection.warning.content"));
  json.put("connectionWarningTitle", i18nHelper.getText("setup.language.dialog.connection.warning.title"));
  json.put("langLabel", i18nHelper.getText("setup.choose.language"));
  json.put("langDesc", i18nHelper.getText("setupdb.server.language.description"));
  json.put("header", i18nHelper.getText("setup.language.dialog.header"));
  return json.toString();
}

代码示例来源:origin: com.atlassian.jira/jira-api

public String toJson()
  {
    JSONObject object = new JSONObject();
    try
    {
      object.put("alt", getAlt());
      object.put("key", getKey());
      object.put("local", getLocal());
      object.put("title", getTitle());
      object.put("url", getUrl());
    }
    catch (JSONException e)
    {
      throw new RuntimeException(e);
    }
    return object.toString();
  }
}

代码示例来源:origin: com.atlassian.jira/jira-core

private void populateJsonWithSetupStatus(final JSONObject json, final AsynchronousJiraSetup.SetupStatus<InstantSetupStrategy.Step> setupStatus)
    throws JSONException
{
  final JSONObject stepsJson = new JSONObject();
  json.put("steps", stepsJson);
  for (final InstantSetupStrategy.Step step : setupStatus.getSteps().keySet())
  {
    stepsJson.put(step.name().toLowerCase(), setupStatus.getSteps().get(step).name().toLowerCase());
  }
  final String errorMessage = setupStatus.getError();
  if (errorMessage != null)
  {
    json.put("errorMessage", errorMessage);
  }
}

代码示例来源:origin: com.atlassian.jira/jira-rest-plugin

@Override
  public Response toResponse(E exception)
  {
    JSONObject json = new JSONObject();
    try
    {
      json.put("errorMessages", Collections.singletonList(exception.getMessage()));
    }
    catch (JSONException e)
    {
      // This is just a realfallback if all goes bad
      return Response.status(Response.Status.BAD_REQUEST).entity(exception.getMessage()).cacheControl(never()).build();
    }
    return Response.status(Response.Status.BAD_REQUEST).entity(json.toString()).type(MediaType.APPLICATION_JSON_TYPE).cacheControl(never()).build();
  }
}

代码示例来源:origin: com.atlassian.jira/jira-core

@ActionViewData
  public String getErrorTextsJson() throws JSONException
  {
    final I18nHelper i18nHelper = ComponentAccessor.getI18nHelperFactory().getInstance(getLocale());
    final JSONObject json = new JSONObject();

    json.put("invalidEmail", i18nHelper.getText("setup.account.form.email.invalid"));
    json.put("emailRequired", i18nHelper.getText("setup.account.form.email.required"));
    json.put("invalidCredentials", i18nHelper.getText("setup.account.invalid.credentials"));
    json.put("passwordRequired", i18nHelper.getText("setup.account.form.password.required"));
    json.put("agreementRequired", i18nHelper.getText("setup.account.form.agreement.required"));
    json.put("fullnameRequired", i18nHelper.getText("setup.account.form.fullname.required"));

    return json.toString();
  }
}

代码示例来源:origin: com.atlassian.jira/jira-core

@Override
public void dismissFlagForUser(String flagKey, ApplicationUser user)
{
  if (user == null || isBlank(flagKey))
  {
    return;
  }
  JSONObject dismissals = getDismissalsForUser(user);
  try
  {
    dismissals.put(flagKey, clock.getCurrentDate().getTime());
    setDismissalsForUser(user, dismissals);
  }
  catch (JSONException e)
  {
    log.debug("Exception occurred while trying to dismiss flag:", e);
  }
}

代码示例来源:origin: com.atlassian.jira.plugins/jira-dvcs-connector-api

@Override
public final String serialize(P payload) {
  try {
    JSONObject json = new JSONObject();
    json.put("repository", payload.getRepository().getId());
    json.put("softSync", payload.isSoftSync());
    json.put("webHookSync", payload.isWebHookSync());
    json.put("version", 1);
    //
    serializeInternal(json, payload);
    //
    return json.toString();
    //
  } catch (Exception e) {
    throw new MessageSerializationException(e, payload);
  }
}

代码示例来源:origin: com.atlassian.jira/jira-core

@Override
public void resetFlagDismissals(String flagKey)
{
  JSONObject resets = getDismissalResets();
  try
  {
    resets.put(flagKey, clock.getCurrentDate().getTime());
    getPropertySet().setText(RESETS_KEY, resets.toString());
  }
  catch (JSONException e)
  {
    log.debug("Exception occurred while trying reset flag dismissal:", e);
  }
}

代码示例来源:origin: com.atlassian.jira/jira-core

public String doSetupFinished() throws IOException, JSONException
{
  final JSONObject json = new JSONObject();
  if (setupAlready() && AsynchronousJiraSetupFactory.getInstance().isSetupFinished(getSetupSessionId()))
  {
    json.put("redirectUrl", getRedirectUrl());
    json.put("SEN", getSupportEntitlementNumber());
  }
  else
  {
    throw new RuntimeException("Setup is not yet finished");
  }
  writeJSONToHttpResponse(json);
  return NONE;
}

相关文章