List of usage examples for com.google.gson JsonArray JsonArray
public JsonArray()
From source file:com.exorath.commons.ItemStackSerialize.java
License:Apache License
public static JsonObject fromItemStack(ItemStack is) { JsonObject itemObject = new JsonObject(); itemObject.addProperty("material", is.getType().name()); itemObject.addProperty("amount", is.getAmount()); itemObject.addProperty("durability", is.getDurability()); if (is.getItemMeta().hasDisplayName()) itemObject.addProperty("displayName", is.getItemMeta().getDisplayName()); if (is.getItemMeta().hasLore()) { JsonArray lore = new JsonArray(); for (String l : is.getItemMeta().getLore()) lore.add(new JsonPrimitive(l)); itemObject.add("lore", lore); }/*w ww . j a va2 s.c o m*/ if (is.getItemMeta().hasEnchants()) { JsonArray enchantments = new JsonArray(); for (Enchantment enchantment : is.getItemMeta().getEnchants().keySet()) { JsonObject ench = new JsonObject(); ench.addProperty("enchantment", enchantment.getName()); ench.addProperty("level", is.getItemMeta().getEnchants().get(enchantment)); enchantments.add(ench); } itemObject.add("enchantments", enchantments); } return itemObject; }
From source file:com.exorath.simpleapi.impl.hub.discovery.serverlist.HubServerImpl.java
License:Apache License
public JsonObject serializeToJson() { JsonObject object = new JsonObject(); object.addProperty("bungee", getBungeeName()); object.addProperty("joinable", isJoinable()); object.addProperty("maxplayers", getPlayerAmount()); JsonArray playersArray = new JsonArray(); players.forEach(p -> playersArray.add(new JsonParser().parse(p.serialize()))); return object; }
From source file:com.exorath.simpleapi.impl.serverlist.GameServerImpl.java
License:Apache License
public static GameServer deserialize(JsonObject object) { GameServerImpl gameServer = new GameServerImpl(object.get("bungee").getAsString()); if (object.has("joinable")) gameServer.setJoinable(object.get("joinable").getAsBoolean()); if (object.has("playable")) gameServer.setPlayable(object.get("playable").getAsBoolean()); if (object.has("maxplayers")) gameServer.setMaxPlayerAmount(object.get("maxplayers").getAsInt()); JsonArray players = object.has("players") ? object.get("players").getAsJsonArray() : new JsonArray(); players.forEach(//w w w. j a va2 s .c o m e -> gameServer.getPlayers().add(SerializedPlayerImpl.deserialize(e.getAsJsonObject().toString()))); JsonArray extraLore = object.has("extra") ? object.get("extra").getAsJsonArray() : new JsonArray(); extraLore.forEach(e -> gameServer.getExtraLore().add(e.getAsString())); return gameServer; }
From source file:com.exorath.simpleapi.impl.serverlist.GameServerImpl.java
License:Apache License
public JsonObject serializeToJson() { JsonObject object = new JsonObject(); object.addProperty("bungee", getBungeeName()); object.addProperty("joinable", isJoinable()); object.addProperty("playable", isPlayable()); object.addProperty("maxplayers", getPlayerAmount()); JsonArray playersArray = new JsonArray(); players.forEach(p -> playersArray.add(new JsonParser().parse(p.serialize()))); JsonArray extraLoreArray = new JsonArray(); extraLore.forEach(line -> extraLoreArray.add(new JsonPrimitive(line))); return object; }
From source file:com.exsoloscript.challonge.gson.ParticipantQueryListAdapter.java
License:Apache License
@Override public JsonElement serialize(List<ParticipantQuery> participantQueryList, Type type, JsonSerializationContext jsonSerializationContext) { JsonObject base = new JsonObject(); JsonArray participantArray = new JsonArray(); for (ParticipantQuery query : participantQueryList) { participantArray.add(jsonSerializationContext.serialize(query)); }/* w ww . ja va 2 s .c o m*/ base.add("participants", participantArray); return base; }
From source file:com.facebook.ads.sdk.BatchRequest.java
License:Open Source License
public String executeInternal() throws APIException, IOException { Map<String, Object> params = new LinkedHashMap<String, Object>(); Map<String, File> files = new HashMap<String, File>(); JsonArray batch = new JsonArray(); params.put("access_token", context.getAccessToken()); if (context.hasAppSecret()) { params.put("appsecret_proof", context.getAppSecretProof()); }// w w w .j a v a2s. com params.put("include_headers", "false"); for (Pair requestEntry : requests) { JsonObject batchElement = new JsonObject(); BatchModeRequestInfo info = requestEntry.request.getBatchModeRequestInfo(); batchElement.addProperty("method", info.method); batchElement.addProperty("relative_url", info.relativeUrl); batchElement.addProperty("name", requestEntry.name); if (info.body != null) { batchElement.addProperty("body", info.body); } if (info.files != null) { JsonObject attachedFiles = new JsonObject(); for (Map.Entry entry : info.files.entrySet()) { File file = (File) entry.getValue(); attachedFiles.addProperty("File" + files.size(), (String) entry.getKey()); files.put("File" + files.size(), file); } batchElement.add("attached_files", attachedFiles); } batch.add(batchElement); } params.put("batch", batch.toString()); params.putAll(files); return APIRequest.getExecutor().sendPost(context.getEndpointBase() + "/", params, context); }
From source file:com.facebook.buck.rules.BuildInfoRecorder.java
License:Apache License
private String toJson(Iterable<String> values) { JsonArray out = new JsonArray(); for (String str : values) { out.add(new JsonPrimitive(str)); }//w w w. j ava 2 s . c o m return out.toString(); }
From source file:com.facebook.buck.rules.BuildInfoRecorder.java
License:Apache License
private String toJson(Multimap<String, String> multimap) { JsonObject out = new JsonObject(); for (Map.Entry<String, Collection<String>> entry : multimap.asMap().entrySet()) { JsonArray values = new JsonArray(); for (String value : entry.getValue()) { values.add(new JsonPrimitive(value)); }/*w ww . j a va 2 s. c o m*/ out.add(entry.getKey(), values); } return out.toString(); }
From source file:com.faces.component.demo.AutocompletePozoAdapter.java
public void convertToJson() { System.out.println("Convertir"); if (listaPozo != null) { jsonArrayPozo = new JsonArray(); for (PozoDto dto : listaPozo) { System.out.println("Convert to Json " + dto.getNombre()); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("name", dto.getId()); jsonObject.addProperty("display", dto.getNombre()); jsonArrayPozo.add(jsonObject); }/*w w w. ja v a2s. com*/ } }
From source file:com.flipkart.android.proteus.view.manager.ProteusViewManagerImpl.java
License:Apache License
private void updateChildrenFromData() { JsonArray dataList = new JsonArray(); ViewGroup parent = ((ViewGroup) view); Result result = Utils.readJson(dataPathForChildren, dataContext.getData(), dataContext.getIndex()); if (result.isSuccess() && null != result.element && result.element.isJsonArray()) { dataList = result.element.getAsJsonArray(); }//from w w w . j av a 2 s . co m int childCount = parent.getChildCount(); View child; if (childCount > dataList.size()) { while (childCount > dataList.size()) { childCount--; child = parent.getChildAt(childCount); if (child instanceof ProteusView) { ((ProteusView) child).getViewManager().destroy(); } parent.removeViewAt(childCount); } } JsonObject data = dataContext.getData(); ProteusView childView; childCount = parent.getChildCount(); for (int index = 0; index < dataList.size(); index++) { if (index < childCount) { child = parent.getChildAt(index); if (child instanceof ProteusView) { ((ProteusView) child).getViewManager().update(data); } } else if (childLayout != null) { childView = layoutBuilder.build(parent, childLayout, data, dataContext.getIndex(), styles); layoutHandler.addView((ProteusView) view, childView); } } }