本文整理汇总了Java中com.google.gson.JsonObject.addProperty方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObject.addProperty方法的具体用法?Java JsonObject.addProperty怎么用?Java JsonObject.addProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.JsonObject
的用法示例。
在下文中一共展示了JsonObject.addProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: overrideDefaultSettings
import com.google.gson.JsonObject; //导入方法依赖的package包/类
/**
* Overrides default setting with the settings fetched fron the community.
*
* @param clientSettings Local settings to be used.
* @param serverSettingJson Settings received from community.
*/
private static void overrideDefaultSettings(JsonObject clientSettings, JsonObject serverSettingJson) {
if (serverSettingJson != null && !serverSettingJson.isJsonNull()) {
if (serverSettingJson.has("response_limit")) {
int limit = serverSettingJson.get("response_limit").getAsInt();
clientSettings.addProperty("limit", limit);
}
if (serverSettingJson.has("discussion_style")) {
JsonArray discussionStyleArr = serverSettingJson.get("discussion_style").getAsJsonArray();
StringBuilder conversationStyleSB = new StringBuilder();
boolean isFirst = true;
conversationStyleSB.append("(");
for (JsonElement styleElem : discussionStyleArr) {
if (isFirst) {
isFirst = false;
} else {
conversationStyleSB.append(", ");
}
conversationStyleSB.append("'").append(styleElem.getAsString()).append("'");
}
conversationStyleSB.append(")");
if (clientSettings.has("whereClauses")) {
JsonArray whereArr = clientSettings.get("whereClauses").getAsJsonArray();
for (JsonElement whereElem : whereArr) {
JsonObject whereObj = whereElem.getAsJsonObject();
if (whereObj.has("key")) {
String key = whereObj.get("key").getAsString();
if (key.equals("conversation.style")) {
whereObj.addProperty("value", conversationStyleSB.toString());
}
}
}
}
}
}
}
示例2: getRequestJsonObject
import com.google.gson.JsonObject; //导入方法依赖的package包/类
private JsonObject getRequestJsonObject(Logger logger, boolean logFailedRequests) {
JsonObject chart = new JsonObject();
chart.addProperty("chartId", chartId);
try {
JsonObject data = getChartData();
if (data == null) {
// If the data is null we don't send the chart.
return null;
}
chart.add("data", data);
} catch (Throwable t) {
if (logFailedRequests) {
logger.warn("Failed to get data for custom chart with id {}", chartId, t);
}
return null;
}
return chart;
}
示例3: testUpdateGroupChat
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Test
public void testUpdateGroupChat() {
JsonObject json = new JsonObject();
json.addProperty("userId", 1);
json.addProperty("datetime", new Date().toString());
json.addProperty("content", "haha");
ArrayList<String> chats = new ArrayList<String>();
chats.add(json.toString());
GroupChat groupChat = new GroupChat(1, chats);
groupChatDao.addGroupChat(groupChat);
groupChat = groupChatDao.getAllGroupChats().get(0);
ArrayList<String> newList = new ArrayList<String>();
newList.add("hhh");
groupChat.setContents(newList);
groupChatDao.updateGroupChat(groupChat);
Assert.assertEquals(groupChatDao.getAllGroupChats().get(0).getContents(), newList);
groupChatDao.deleteGroupChat(groupChat);
}
示例4: writeObservationsToJSON
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
public void writeObservationsToJSON(JsonObject json, MissionInit missionInit)
{
// Return a string that is unique for every cell on the x/z plane (ignores y)
EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
// getPosition() rounds to int.
int x = player.getPosition().getX();
int z = player.getPosition().getZ();
json.addProperty("cell", "(" + x + "," + z + ")");
}
示例5: addAggStdInfo
import com.google.gson.JsonObject; //导入方法依赖的package包/类
private static void addAggStdInfo(JsonObject jo, List<JsonObject> samples) {
// beginMsec, endMsec, nSamples
long msec = samples.get(0).get(KEY_TS).getAsLong();
long msec2 = samples.get(samples.size()-1).get(KEY_TS).getAsLong();
int nSamples = samples.size();
jo.addProperty(KEY_TS, msec2);
jo.addProperty(KEY_AGG_BEGIN_TS, msec);
jo.addProperty(KEY_AGG_COUNT, nSamples);
}
示例6: banNote
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@RequestMapping("/banNote")
@ResponseBody
public String banNote(@RequestParam("verifyId") int verifyId) {
adminService.banNote(verifyId);
JsonObject obj = new JsonObject();
obj.addProperty("result","success");
return new Gson().toJson(obj);
}
示例7: onSerialization
import com.google.gson.JsonObject; //导入方法依赖的package包/类
protected void onSerialization(JsonObject data)
{
if (this.getValue() != null)
{
data.addProperty("uuid", ((GameProfile)this.getValue()).getId() == null ? "" : ((GameProfile)this.getValue()).getId().toString());
data.addProperty("name", ((GameProfile)this.getValue()).getName());
super.onSerialization(data);
data.addProperty("level", (Number)Integer.valueOf(this.permissionLevel));
data.addProperty("bypassesPlayerLimit", Boolean.valueOf(this.bypassesPlayerLimit));
}
}
示例8: tagCreate
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
public WxUserTag tagCreate(String name) throws WxErrorException {
String url = API_URL_PREFIX + "/create";
JsonObject json = new JsonObject();
JsonObject tagJson = new JsonObject();
tagJson.addProperty("name", name);
json.add("tag", tagJson);
String responseContent = this.wxMpService.post(url, json.toString());
return WxUserTag.fromJson(responseContent);
}
示例9: onSerialization
import com.google.gson.JsonObject; //导入方法依赖的package包/类
protected void onSerialization(JsonObject data)
{
data.addProperty("created", dateFormat.format(this.banStartDate));
data.addProperty("source", this.bannedBy);
data.addProperty("expires", this.banEndDate == null ? "forever" : dateFormat.format(this.banEndDate));
data.addProperty("reason", this.reason);
}
示例10: onSerialization
import com.google.gson.JsonObject; //导入方法依赖的package包/类
protected void onSerialization(JsonObject data)
{
if (this.getValue() != null)
{
data.addProperty("uuid", ((GameProfile)this.getValue()).getId() == null ? "" : ((GameProfile)this.getValue()).getId().toString());
data.addProperty("name", ((GameProfile)this.getValue()).getName());
super.onSerialization(data);
data.addProperty("level", (Number)Integer.valueOf(this.field_152645_a));
data.addProperty("bypassesPlayerLimit", Boolean.valueOf(this.field_183025_b));
}
}
示例11: serialize
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
public JsonElement serialize(WidgetPane src, JsonSerializationContext context) {
JsonObject object = new JsonObject();
object.addProperty("gridSize", src.getTileSize());
object.addProperty("hgap", src.getHgap());
object.addProperty("vgap", src.getVgap());
JsonObject tiles = new JsonObject();
for (Tile<?> tile : src.getTiles()) {
String x = GridPane.getColumnIndex(tile).toString();
String y = GridPane.getRowIndex(tile).toString();
String coordinate = String.join(",", x, y);
JsonObject tileObject = new JsonObject();
tileObject.add("size", context.serialize(tile.getSize(), TileSize.class));
tileObject.add("content", context.serialize(tile.getContent(), tile.getContent().getClass()));
tiles.add(coordinate, tileObject);
}
object.add("tiles", tiles);
return object;
}
示例12: serialize
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
public JsonElement serialize(
final RecipeVersion recipeVersion, final Type type, final JsonSerializationContext context) {
Preconditions.checkNotNull(recipeVersion);
Preconditions.checkNotNull(type);
Preconditions.checkNotNull(context);
final JsonObject jsonObject = new JsonObject();
final JsonElement sourceElement = Either.join(
recipeVersion.source,
context::serialize,
context::serialize);
jsonObject.add("source", sourceElement);
if (recipeVersion.target.isPresent()) {
jsonObject.addProperty("target", recipeVersion.target.get());
}
if (recipeVersion.dependencies.map(DependencyGroup::any).orElse(false)) {
jsonObject.add("dependencies", context.serialize(recipeVersion.dependencies.get()));
}
if (recipeVersion.buckResource.isPresent()) {
jsonObject.add("buck", context.serialize(recipeVersion.buckResource.get(), RemoteFile.class));
}
return jsonObject;
}
示例13: sendMessage
import com.google.gson.JsonObject; //导入方法依赖的package包/类
/**
* @param content Content of the message to be sent
* @return The newly sent message.
*/
public Message sendMessage(String content)
{
JsonObject json = new JsonObject();
json.addProperty("content", content);
return (Message) DiscordAPI.request("POST", "/channels/" + id + "/messages", json.toString(), new Message());
}
示例14: shortJson
import com.google.gson.JsonObject; //导入方法依赖的package包/类
/**
* @see GenericDefinition#shortJson()
*/
@Override
public JsonElement shortJson() {
JsonObject json = new JsonObject();
json.addProperty("band", band.getName());
json.addProperty("region", region.getId());
return json;
}
示例15: updateFromSync
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Test
public void updateFromSync() {
JsonObject data = new JsonObject();
data.addProperty("type", "m.presence");
JsonObject content = new JsonObject();
content.addProperty("presence", "offline");
data.add("content", content);
user.update(data);
Assert.assertEquals("User object did not parse presence sync data", user.getPresence(), User.Presence.OFFLINE);
}