本文整理了Java中com.atlassian.jira.util.json.JSONObject.toString()
方法的一些代码示例,展示了JSONObject.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.toString()
方法的具体详情如下:
包路径:com.atlassian.jira.util.json.JSONObject
类名称:JSONObject
方法名:toString
[英]Make a JSON text of this JSONObject. For compactness, no whitespace is added. If this would not result in a syntactically correct JSON text, then null will be returned instead.
Warning: This method assumes that the data structure is acyclical.
[中]生成此JSONObject的JSON文本。对于紧凑性,不添加空格。如果这不会导致语法正确的JSON文本,那么将返回null。
警告:此方法假定数据结构是非循环的。
代码示例来源:origin: com.atlassian.jira/jira-api
/**
* Make a pretty-printed JSON text of this JSONObject.
* <p/>
* Warning: This method assumes that the data structure is acyclic.
*
* @param indentFactor The number of spaces to add to each level of
* indentation.
* @return a printable, displayable, portable, transmittable
* representation of the object, beginning
* with <code>{</code> <small>(left brace)</small> and ending
* with <code>}</code> <small>(right brace)</small>.
* @throws JSONException If the object contains an invalid number.
*/
public String toString(final int indentFactor) throws JSONException
{
return toString(indentFactor, 0);
}
代码示例来源:origin: com.atlassian.jira/jira-core
@Override
public boolean apply(final JSONObject json)
{
final long jsonLength = json.toString().length();
if((currentLength + jsonLength + ADDITIONAL_CHARS_PER_ENTRY < maxLength))
{
currentLength += jsonLength + ADDITIONAL_CHARS_PER_ENTRY;
return true;
}
return false;
}
}
代码示例来源:origin: com.atlassian.jira/jira-core
private void writeJSONToHttpResponse(final JSONObject json) throws IOException
{
final HttpServletResponse response = getHttpResponse();
response.setContentType("application/json");
final String result = json.toString();
response.getWriter().write(result);
response.getWriter().flush();
}
代码示例来源:origin: com.atlassian.jira/jira-core
private EntityPropertyService.PropertyInput toPropertyInput(final JSONObject jsonObject)
{
return new EntityPropertyService.PropertyInput(jsonObject.toString(), PROJECT_SEARCH_REQUESTS_KEY);
}
代码示例来源:origin: com.atlassian.jira/jira-core
private String getFilterAsJsonString(final UserFilter filter, final Collection<ProjectRole> allProjectRoles)
{
try
{
return UserFilterUtils.toJson(filter, projectRoleManager).toString();
}
catch (final JSONException e)
{
log.error("Unable to create JSON representation of user filter: " + e.getMessage(), e);
return "";
}
}
代码示例来源:origin: com.atlassian.jira/jira-core
private void setDismissalsForUser(ApplicationUser user, JSONObject dismissals)
{
try
{
userPreferencesManager.getExtendedPreferences(user).setText(DISMISSALS_KEY, dismissals.toString());
}
catch (AtlassianCoreException e)
{
log.debug("Exception occurred while trying to dismiss flag:", e);
}
}
}
代码示例来源:origin: com.atlassian.jira/jira-api
@Override
public EntityPropertyBean apply(final Map<String, Object> entityPropertyBean)
{
final String key = (String) entityPropertyBean.get("key");
final Map<String, Object> value = (Map<String, Object>) entityPropertyBean.get("value");
return new EntityPropertyBean(key, new JSONObject(value).toString(), null);
}
}));
代码示例来源: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
@Override
protected void doFilter(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain)
throws IOException, ServletException
{
try
{
final JSONObject json = new JSONObject();
response.setContentType("application/json");
final String sessionId = (String) request.getSession().getAttribute("setup-session-id");
final InstantSetupStrategy.Step step = InstantSetupStrategy.Step.valueOf(request.getParameter("askingAboutStep").toUpperCase());
populateJsonWithSetupStatus(json, AsynchronousJiraSetupFactory.getInstance().getStatusOnceStepIsDone(sessionId, step));
final String result = json.toString();
response.getWriter().write(result);
response.getWriter().flush();
}
catch (final JSONException e)
{
throw new ServletException(e);
}
}
代码示例来源:origin: com.atlassian.jira/jira-core
private boolean validCommentProperty(final CommentParameters commentParameters, ErrorCollection errorCollection)
{
for (Map.Entry<String, JSONObject> property : commentParameters.getCommentProperties().entrySet())
{
errorCollection.addErrorCollection(commentPropertyService.validatePropertyInput(new PropertyInput(property.getValue().toString(), property.getKey())));
}
return !errorCollection.hasAnyErrors();
}
代码示例来源:origin: com.atlassian.jira/jira-core
private void setProperties(final ApplicationUser applicationUser, final Comment comment, Map<String, JSONObject> properties)
{
for (Map.Entry<String, JSONObject> property : properties.entrySet())
{
jsonEntityPropertyManager.put(applicationUser, commentPropertyHelper.getEntityPropertyType().getDbEntityName(),
comment.getId(), property.getKey(), property.getValue().toString(), commentPropertyHelper.createSetPropertyEventFunction(), true);
}
}
代码示例来源:origin: com.atlassian.jira/jira-core
public String doConnectionCheck() throws IOException
{
final HttpServletResponse response = getHttpResponse();
final JSONObject json = new JSONObject();
response.setContentType("application/json");
databaseOption = "external";
doValidation();
try
{
json.put("data", getSoyDataForConnectionCheck());
response.getWriter().write(json.toString());
}
catch (JSONException e)
{
response.getWriter().write("{}");
}
finally
{
response.getWriter().flush();
}
return NONE;
}
代码示例来源: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.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 doGetInstalledLocales() throws JSONException, IOException
{
final HttpServletResponse response = getHttpResponse();
final LocaleManager localeManager = ComponentAccessor.getComponentOfType(LocaleManager.class);
final Set<Locale> installedLocales = localeManager.getInstalledLocales();
final JSONObject jsonObject = new JSONObject();
final JSONObject locales = new JSONObject();
for (Locale installedLocale : installedLocales)
{
locales.put(installedLocale.toString(), installedLocale.getDisplayName(installedLocale));
}
jsonObject.put("currentLocale", getDefaultServerLanguage());
jsonObject.put("locales", locales);
response.setContentType("application/json");
response.getWriter().write(jsonObject.toString());
response.getWriter().flush();
return NONE;
}
代码示例来源:origin: com.atlassian.jira/jira-core
public void validateCommentProperties(Map<String, Object> properties, ErrorCollection errorCollection)
{
try
{
final ImmutableMap<String, JSONObject> commentProperties = getCommentPropertiesFromParameters(properties);
for (Map.Entry<String, JSONObject> property : commentProperties.entrySet())
{
EntityPropertyService.PropertyInput propertyInput = new EntityPropertyService.PropertyInput(property.getValue().toString(), property.getKey());
errorCollection.addErrorCollection(commentPropertyService.validatePropertyInput(propertyInput));
}
}
catch (JSONException e)
{
errorCollection.addErrorMessage(i18nFactory.getInstance(authenticationContext.getUser()).getText("jira.properties.service.invalid.json", properties.get(PARAM_COMMENT_PROPERTY)));
}
}
代码示例来源: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.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
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-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();
}
}
内容来源于网络,如有侵权,请联系作者删除!